Binary Search Trees Flashcards

1
Q

what is a binary search tree?

A

1 - binary tree (at most have 2 children)
2 - left subtrees are lesser than the parent
3 - right subtrees are greater than the parent

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

where do u start in a BST?

A

we always start at the root of the tree

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

what to do when u want to delete a node with two children?

A

you must search for the smallest bigger leaf than the node u want to remove and replace it with that node and then delete it

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

what to do with duplicate values?

A

it depends on the application and if u insert it it would be better to insert it into the right of the node which makes it a stable tree

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

what is the structure of a BST?

A

it has a linked list structure

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

what does each node need?

A

1 - a value
2 - a parent
3 - a left child
4 - a right child

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

what are the types of traversal in BST?

A

1 - PreOrder (DFS)
2 - PostOrder (DFS)
3 - InOrder
4 - Level Order (BDS)

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

what is a PreOrder Traversal?

A

visit yourself
then visit all your left subtree
then visit all your right subtree

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

what is a PostOrder Traversal?

A

then visit all your left subtree
then visit all your right subtree
visit yourself

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

what is a InOrder Traversal?

A

then visit all your left subtree
visit yourself
then visit all your right subtree

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

what is a Level Order Traversal?

A

it’s breadth first search where u can’t use recursion u must use a queue or a list
u add an element to the queue and go and remove it and when u remove it u add the children to the list as long as the queue is not empty

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

why is BST better than binary search on an array?

A

cuz in an array insertion and removal is harder

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

how to search in a BST?

A

1 - compare for the current element if they are equal return
2 - if it’s smaller go to the left
3 - if it’s bigger go to the right

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

what is the airport reservation system problem?

A

u have an airport with landing zones and u want the airplanes to request for landing in T time to the set R and keep track of K (available time to land) and u want to delete from R set when a plane lands all of that in log(N)

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

how to find min()

A

go to the left until there is no left

O(H) where h is the height

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

how to find max()

A

go to the right until there is no right

O(H) where h is the height

17
Q

what is an augmented BST?

A

it’s a BST with a little more information in each node like the number of subtrees that each node has under it