Recall & Review
beginner Click to reveal answer
What is the minimum element in a Binary Search Tree (BST)?
The minimum element in a BST is the leftmost node because all smaller values are stored to the left.
beginner Click to reveal answer
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 is the minimum.
intermediate Click to reveal answer
Why does the minimum element in a BST always lie in the left subtree?
Because BST property states left child nodes have smaller values than their parents, so the smallest value is found by going left repeatedly.
intermediate Click to reveal answer
Rust code snippet to find minimum element in a BST node:
fn find_min(node: &Option) -> Option<i32> {
match node {
Some(n) => {
if n.left.is_none() {
Some(n.val)
} else {
find_min(&n.left)
}
}
None => None,
}
}
beginner Click to reveal answer
What happens if you call find_min on an empty BST?
The function returns None because there is no node to find a minimum value from.
Where is the minimum element located in a BST?
✗ Incorrect
The minimum element is always the leftmost node in a BST.
What is the first step to find the minimum element in a BST?
✗ Incorrect
You start at the root and move to the left child repeatedly to find the minimum.
If a BST node has no left child, what does that node represent?
✗ Incorrect
A node with no left child is the minimum element in that subtree.
What does the Rust function find_min return if the BST is empty?
✗ Incorrect
It returns None because there is no node to find a minimum value.
Why is it efficient to find the minimum element in a BST?
✗ Incorrect
You only move left until no left child exists, so it is efficient.
Explain how to find the minimum element in a Binary Search Tree.
Think about the BST property and left children.
You got /4 concepts.
Write a simple Rust function to find the minimum element in a BST and explain its logic.
Use Option and pattern matching.
You got /4 concepts.
