Recall & Review
beginner
What is a Binary Search Tree (BST)?
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?
✗ 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?
✗ 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?
✗ 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?
✗ 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?
✗ 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.