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 than the parent's value.
Click to reveal answer
beginner
How do you find the minimum element in a BST?
Start at the root and keep moving to the left child until you reach a node with no left child. That node contains the minimum value.
Click to reveal answer
beginner
Why does moving left in a BST lead to the minimum element?
Because in a BST, left children always have smaller values than their parents, so the leftmost node is the smallest.
Click to reveal answer
intermediate
What is the time complexity of finding the minimum element in a BST?
The time complexity is O(h), where h is the height of the tree. In the best case (balanced tree), it's O(log n), and in the worst case (skewed tree), it's O(n).
Click to reveal answer
intermediate
Show the C code snippet to find the minimum element in a BST.
Loop runs while root->left == NULL, which means it stops if left child exists, so it never moves left.
Step 2: Correct loop condition
It should run while root->left != NULL to move left until no left child.
Final Answer:
Loop condition should be root->left != NULL -> Option A
Quick Check:
Traverse left while left child exists [OK]
Hint: Loop must continue while left child exists [OK]
Common Mistakes:
Using == NULL instead of != NULL in loop
Ignoring NULL root check
Confusing left and right pointers
5. Given a BST where some nodes have only right children, how would you modify the findMin function to safely find the minimum element without causing a runtime error if the tree is empty?
hard
A. Traverse right child instead of left child
B. Return root->data immediately without traversal
C. Use recursion without base case
D. Add a check at start: if(root == NULL) return NULL; then traverse left
Solution
Step 1: Handle empty tree case
Check if root is NULL at start to avoid dereferencing NULL pointer.
Step 2: Traverse left children safely
If root is not NULL, move left while left child exists to find minimum.
Final Answer:
Add a check at start: if(root == NULL) return NULL; then traverse left -> Option D
Quick Check:
Check NULL root before traversal [OK]
Hint: Always check for NULL root before traversal [OK]
Common Mistakes:
Not checking for empty tree causing crash
Traversing right child for minimum
Missing base case in recursion
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.