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 do you find the minimum element in a BST?
Start at the root and keep moving to the left child until there is no left child. The last node you reach is the minimum element.
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 holds the smallest value.
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
beginner
Show the JavaScript code snippet to find the minimum element in a BST.
function findMin(root) {
if (!root) return null;
while (root.left) {
root = root.left;
}
return root.value;
}
Click to reveal answer
In a BST, where is the minimum element located?
AAt the leftmost node
BAt the rightmost node
CAt the root node
DAt any leaf node
✗ Incorrect
The minimum element is always at the leftmost node because left children have smaller values.
What should you do if the BST is empty when finding the minimum element?
AThrow an error
BReturn the root value
CReturn zero
DReturn null or indicate no minimum
✗ Incorrect
If the BST is empty (root is null), there is no minimum element, so return null.
What is the time complexity to find the minimum element in a balanced BST with n nodes?
AO(log n)
BO(n log n)
CO(1)
DO(n)
✗ Incorrect
In a balanced BST, height h is about log n, so finding minimum takes O(log n) time.
Which of these steps is NOT part of finding the minimum element in a BST?
AStart at the root
BKeep moving to the right child
CStop when no left child exists
DReturn the last node's value
✗ Incorrect
You move to the left child to find the minimum, not the right.
What does the function return if the BST has only one node?
AThe value of the root's left child
Bnull
CThe value of the single node
DUndefined
✗ Incorrect
If there is only one node, it is the minimum, so the function returns its value.
Explain step-by-step how to find the minimum element in a Binary Search Tree.
Think about how BST organizes smaller values on the left.
You got /4 concepts.
Write a simple JavaScript function to find the minimum element in a BST and explain how it works.
Use a while loop to move left until no more left child.
You got /4 concepts.
Practice
(1/5)
1. In a Binary Search Tree (BST), where is the minimum element always located?
easy
A. At the rightmost node
B. At the root node
C. At the leftmost node
D. At any leaf node
Solution
Step 1: Understand BST property
In a BST, left child nodes have smaller values than their parents.
Step 2: Locate minimum element
The smallest value is found by going as far left as possible.
Final Answer:
At the leftmost node -> Option C
Quick Check:
Minimum = leftmost node [OK]
Hint: Minimum is always the leftmost node in BST [OK]
Common Mistakes:
Thinking minimum is at root
Confusing leftmost with rightmost
Assuming minimum can be any leaf
2. Which of the following JavaScript code snippets correctly finds the minimum element in a BST node structure where each node has left and value properties?
easy
A. function findMin(node) { while(node.left) { node = node.left; } return node.value; }
B. function findMin(node) { while(node.right) { node = node.right; } return node.value; }
C. function findMin(node) { return node.value; }
D. function findMin(node) { if(node.right) return findMin(node.right); else return node.value; }
Solution
Step 1: Check traversal direction
Minimum is found by moving left, so loop should check node.left.
Step 2: Verify code correctness
function findMin(node) { while(node.left) { node = node.left; } return node.value; } loops while node.left exists, then returns node.value, which is correct.
Final Answer:
function findMin(node) { while(node.left) { node = node.left; } return node.value; } -> Option A
Quick Check:
Traverse left until no left child [OK]
Hint: Loop left child nodes to find minimum [OK]
Common Mistakes:
Looping right child instead of left
Returning node.value without traversal
Recursing on right child for minimum
3. Given the BST below and the function findMin that finds the minimum value, what will be the output?
A. It incorrectly traverses right child instead of left
B. It does not return the node value
C. It causes infinite loop
D. It throws syntax error
Solution
Step 1: Analyze traversal direction
The code moves to node.right repeatedly, which finds the maximum, not minimum.
Step 2: Identify correct traversal for minimum
Minimum requires moving to node.left, so the bug is wrong direction.
Final Answer:
It incorrectly traverses right child instead of left -> Option A
Quick Check:
Minimum = leftmost, not rightmost [OK]
Hint: Minimum is leftmost, not rightmost traversal [OK]
Common Mistakes:
Confusing left and right child traversal
Assuming right child leads to minimum
Not testing code with example trees
5. You want to find the minimum element in a BST that may be empty (null). Which of the following improved functions correctly handles this edge case and returns null if the tree is empty?
hard
A. function findMin(node) { while(node.left) { node = node.left; } return node.value; }
B. function findMin(node) { if(!node) return null; while(node.left) { node = node.left; } return node.value; }
C. function findMin(node) { if(node.left) return findMin(node.left); else return node.value; }
D. function findMin(node) { if(!node.left) return null; else return findMin(node.left); }
Solution
Step 1: Check for empty tree
function findMin(node) { if(!node) return null; while(node.left) { node = node.left; } return node.value; } returns null immediately if node is null, handling empty tree.
Step 2: Traverse left children safely
Then it loops left until no left child, returning minimum value correctly.
Final Answer:
function findMin(node) { if(!node) return null; while(node.left) { node = node.left; } return node.value; } -> Option B
Quick Check:
Check null first, then traverse left [OK]
Hint: Check for null before traversal to avoid errors [OK]
Common Mistakes:
Not checking for null input
Returning null incorrectly when node exists
Recursing without base case for null
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.