A BST is a tree where each node has at most two children. The left child's value is less than the parent's value, and the right child's value is greater. This helps in fast searching.
Click to reveal answer
beginner
How does the search operation work in a BST?
Start at the root. If the value equals the node's value, stop. If smaller, go left. If larger, go right. Repeat until found or no more nodes.
Click to reveal answer
beginner
Why is BST search faster than searching in a list?
BST search skips half of the tree at each step by choosing left or right child based on comparison, unlike a list which checks each item one by one.
Click to reveal answer
intermediate
What is the time complexity of searching in a balanced BST?
The time complexity is O(log n) because each step halves the search space in a balanced BST.
Click to reveal answer
beginner
What happens if the value is not found in the BST during search?
The search reaches a null child (no node), meaning the value is not in the tree.
Click to reveal answer
In a BST, if the search value is less than the current node's value, where do you go next?
ARoot node
BRight child
CParent node
DLeft child
✗ Incorrect
If the search value is less, you move to the left child because all left children have smaller values.
What is the best case time complexity of searching in a BST?
AO(n)
BO(log n)
CO(1)
DO(n log n)
✗ Incorrect
Best case is O(1) when the root node itself contains the search value.
If a BST is not balanced, what can happen to the search time?
AIt becomes O(n)
BIt becomes O(1)
CIt stays O(log n)
DIt becomes O(n log n)
✗ Incorrect
If the BST is skewed (like a linked list), search time can degrade to O(n).
What is the first step in searching a value in a BST?
ACheck the left child
BCompare with the root node
CCheck the right child
DInsert the value
✗ Incorrect
Search always starts by comparing the value with the root node.
If the search value is greater than the current node's value, where do you move next?
ARight child
BLeft child
CParent node
DRoot node
✗ Incorrect
You move to the right child because all right children have greater values.
Explain the step-by-step process of searching a value in a BST.
Think about how you decide which child to visit next.
You got /5 concepts.
Describe why BST search is more efficient than searching in an unsorted list.
Focus on how BST structure helps reduce search steps.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the search operation in a Binary Search Tree (BST)?
easy
A. To find whether a given value exists in the BST
B. To insert a new node in the BST
C. To delete a node from the BST
D. To traverse all nodes in the BST
Solution
Step 1: Understand the purpose of search in BST
The search operation is used to check if a specific value is present in the BST.
Start at root 10, 15 > 10, go right to 20. Then 15 < 20, go left to 15.
Step 2: Check node data at 15
Node data matches key 15, so function returns true and prints "Found".
Final Answer:
Found -> Option A
Quick Check:
Key found in BST = Found [OK]
Hint: Follow BST rules left/right to find key [OK]
Common Mistakes:
Stopping search too early
Confusing left and right child directions
Assuming key not found when present
4. Identify the error in the following BST search function and choose the correct fix:
bool search(Node* root, int key) {
if (root == nullptr) return false;
if (root->data == key) return true;
if (key > root->data) return search(root->left, key);
else return search(root->right, key);
}
medium
A. Remove base case for nullptr
B. Change return type to int
C. Swap left and right in recursive calls; should be key < root->data for left
D. Add print statements for debugging
Solution
Step 1: Analyze recursive calls logic
For BST, if key < root->data, search left; if key > root->data, search right.
Step 2: Identify incorrect direction
Code searches left when key > root->data, which is wrong. Left subtree has smaller values.
Step 3: Correct the recursive calls
Swap left and right calls: if (key < root->data) search left; else search right.
Final Answer:
Swap left and right in recursive calls; should be key < root->data for left -> Option C
Quick Check:
BST property fixes search direction [OK]
Hint: Left subtree < node, right subtree > node [OK]
Common Mistakes:
Mixing left and right subtree directions
Ignoring base case
Changing return type unnecessarily
5. Given a BST with nodes inserted in this order: 25, 15, 50, 10, 22, 35, 70. You want to search for the value 22. How many nodes will the search function visit before finding 22?
hard
A. 2
B. 5
C. 4
D. 3
Solution
Step 1: Build BST structure from insertion order
Insert 25 (root), then 15 (left of 25), 50 (right of 25), 10 (left of 15), 22 (right of 15), 35 (left of 50), 70 (right of 50).
Step 2: Trace search path for 22
Start at 25 (visit 1), 22 < 25 go left to 15 (visit 2), 22 > 15 go right to 22 (visit 3), found key.
Final Answer:
3 -> Option D
Quick Check:
Nodes visited = 3 [OK]
Hint: Count nodes visited following BST search path [OK]
Common Mistakes:
Counting nodes not visited
Misplacing nodes in BST
Stopping count before finding key
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.