Binary_Search_Tree_Algorithms_Flashcards

(5 cards)

1
Q

How does a binary search tree (BST) work?

A

Each node has at most two children; the left child contains smaller values, the right child contains larger values.

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

What is the main advantage of using a binary search tree?

A

It allows efficient searching, insertion, and deletion with average time complexity of O(log n) if balanced.

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

What is the difference between searching in a BST and an array?

A

BST uses node comparisons and has average O(log n) complexity; array search is linear (O(n)) unless it’s a binary search on a sorted array.

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

What are the steps to insert a value into a binary search tree?

A

Compare the value to the current node, go left if smaller or right if larger, and repeat until an empty position is found.

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

What are the steps to remove a node from a binary search tree?

A

Handle three cases: node has no children (remove directly), one child (replace with child), or two children (replace with in-order successor or predecessor).

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