A Binary Search Tree is a tree data structure where each node has at most two children. For every node, all nodes in its left subtree have smaller values, and all nodes in its right subtree have larger values.
Click to reveal answer
beginner
How do you find the minimum element in a BST?
To 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 parent nodes. So, moving left repeatedly leads to 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 BST. In the best case (balanced tree), it's O(log n). In the worst case (skewed tree), it's O(n).
Click to reveal answer
beginner
Show the Python code snippet to find the minimum element in a BST node.
def find_min(node):
current = node
while current.left is not None:
current = current.left
return current.data
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?
AReturn the rightmost node
BReturn the root node
CReturn None or indicate no minimum
DThrow an error always
✗ Incorrect
If the BST is empty, there is no minimum element, so returning None or a similar indication is correct.
What is the first step to find the minimum element in a BST?
AStart at the middle node
BStart at the right child
CStart at the leaf node
DStart at the root node
✗ Incorrect
You always start at the root and move left to find the minimum.
If a BST has only one node, what is the minimum element?
AThe single node itself
BNo minimum element
CThe left child
DThe right child
✗ Incorrect
With only one node, that node is both the minimum and maximum.
What is the time complexity to find the minimum element in a balanced BST with n nodes?
AO(n)
BO(log n)
CO(1)
DO(n log n)
✗ Incorrect
In a balanced BST, height h is about log n, so finding minimum takes O(log n).
Explain step-by-step how to find the minimum element in a BST.
Think about the BST property and left children.
You got /4 concepts.
Write a simple Python function to find the minimum element in a BST and explain how it works.
Use a while loop and check 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 leftmost node
B. At the rightmost node
C. At the root node
D. At any leaf node
Solution
Step 1: Understand BST property
In a BST, left child nodes have smaller values than their parents, so the smallest value is always towards the left.
Step 2: Locate minimum element
By moving left from the root repeatedly until no more left child exists, we reach the minimum element.
Final Answer:
At the leftmost node -> Option A
Quick Check:
Minimum element = leftmost node [OK]
Hint: Minimum is always the leftmost node in BST [OK]
Common Mistakes:
Confusing minimum with root node
Thinking minimum is at rightmost node
Assuming minimum can be any leaf
2. Which of the following Python code snippets correctly finds the minimum element in a BST node named root?
easy
A. while root.right is not None:
root = root.right
print(root.val)
B. while root.left is not None:
root = root.left
print(root.val)
C. if root.left is None:
print(root.val)
D. print(min(root.val, root.left.val))
Solution
Step 1: Check loop for minimum search
while root.left is not None:
root = root.left
print(root.val) correctly moves left while left child exists, which is how to find minimum in BST.
Step 2: Verify other options
while root.right is not None:
root = root.right
print(root.val) moves right (wrong for minimum), C only checks once, D uses min on values without traversal.
Final Answer:
while root.left is not None:
root = root.left
print(root.val) -> Option B
Quick Check:
Traverse left until None = while root.left is not None:
root = root.left
print(root.val) [OK]
Hint: Traverse left child until None to find minimum [OK]
Common Mistakes:
Traversing right child instead of left
Not using a loop to reach leftmost node
Using min() function incorrectly on nodes
3. What will be the output of the following code snippet?