Concept Flow - BST Find Minimum Element
Start at root
Check if left child exists?
No→Current node is minimum
Yes
Move to left child
Repeat check
Start at the root node and keep moving left until no left child exists; that node is the minimum.
func findMin(root *Node) *Node {
current := root
for current.Left != nil {
current = current.Left
}
return current
}| Step | Operation | Current Node | Left Child Exists? | Pointer Changes | Visual State |
|---|---|---|---|---|---|
| 1 | Start at root | 20 | Yes | current = root (20) | 20 / \ 10 30 |
| 2 | Check left child | 20 | Yes | Move current to left child (10) | 20 / \ 10 30 |
| 3 | Check left child | 10 | Yes | Move current to left child (5) | 20 / \ 10 30 / 5 |
| 4 | Check left child | 5 | No | Stop, current is minimum | 20 / \ 10 30 / 5 |
| 5 | Return current | 5 | No | Return node with value 5 | Minimum element found: 5 |
| Variable | Start | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|
| current | 20 (root) | 10 | 5 | 5 | 5 |
BST Find Minimum Element: - Start at root node - While left child exists, move left - When no left child, current node is minimum - Return current node - Works because BST left subtree has smaller values