BST Flashcards

binary search tree

1
Q

EACH VERTEX CAN HAVE UP TO 2 CHILDREN

A

2 CHILDREN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

LEFT - SMALL , RIGHT-LARGER

A

DUPLICATES ARE STORED AS FREQUENCY - MULTISET

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

AVL trees are self balancing binary tree with height O(log (n))

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Find Successor

A
  1. if RIGHT exist, then min in the right subtree
  2. no RIGTH exist, go to parent and traverse until the the first right turn from searching. Then parent of that right successor. Basically, it gives the first max of V (right turn)
  3. if MAX in BST, then we go until root and not found. Result is -1

RIGHT (find min) or parent first right’s parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Find Predecessor

A
  1. if left exist, then max in the subtree
  2. if left not exist, parents’ first left, then parent
  3. if no left find until ROOT then -1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

PRE, IN, POST

A

PPE- print as we visit FIRST time
IN - print as we visit SECOND time
POST - print as we visit THIRD time
https://www.youtube.com/watch?v=WLvU5EQVZqY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

BST element rank

A

Use IN ORDER to write in sorted order and find the index - starting with 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ascending order

A

In order traversal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Kth-smallest

A

Use ranking BST
https://www.youtube.com/watch?v=adAQs2FNuFo for later exam study

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Static/Dynamic

A

If no update, insert or delete then static. If there is then dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

lower-bound

A

smallest value that is bigger than the value V to be found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

search/lower_bound/searchMin/SearchMax time complexity

A

O(h)
h- as tall as N for normal BST

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Skewed BST

A

only RIGHT or only LEFT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

time complexity: O(N Log(N)) to insertions of N elements and then O(N) for in-order to get sorted

A

But rarely used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Height is ZERO based

A

root - 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

in normal BST, O(h) for finding find for others

A

insertion O(1) as at the leaf
deletion of no child - O(1)
deletion with one child - O(1)
deletion with two child - O(h) for finding successor

17
Q

skewed BST is nothing but

A

linked list

18
Q

Height

A

Number of edges under the rode to leaf
-max route

19
Q

AVL lower bound height

A

log2(N)

20
Q

AVL two soviet inventors

A

Georgy Adelson-Velskii
Evgenii Landis
1962

21
Q

AVL height

A

< 2 * log(N)

22
Q

AVL BF - balance factor

A

number of left edges - number of right edges. And should be in {-1,0,1}
https://www.youtube.com/watch?v=u3OVSkuOdqI

23
Q

rotations

A

More on left -> rotate right
More on right -> rotate left

LL -> Left rotation
RR -> Right rotation
LR -> from root left followed by right
so, first child left rotation
then right rotation
RL -> from root right followed by left