Traverse
Minimum element in BST
Basic·
3 Approachesclick to switch
1
DFS (Recursive)
O(h)
O(h)
2
DFS (Iterative)
O(h)
O(h)
3
BFS
O(n)
O(w)
FIG. MINIMUM ELEMENT BST● INTERACTIVE
visualization loads as you reach it
- Time
- O(h)
dfsonly ever recurses intonode.left, nevernode.right, so it walks the left spine down to the leftmost node - the tree's heighth.- Space
- O(h)
- The recursion stack depth equals the length of that left spine,
h.
285. Inorder Successor in BST
Medium·
2 Approachesclick to switch
1
DFS (Recursive)
O(h)
O(h)
2
DFS (Iterative)
O(h)
O(h)
FIG. INORDER SUCCESSOR IN BST● INTERACTIVE
visualization loads as you reach it
- Time
- O(h)
recursionmoves tonode.rightornode.leftexactly once per level based on the comparison withp.val, so it follows a single root-to-leaf path of lengthh.- Space
- O(h)
- The recursion call stack grows one frame per level, so it never exceeds the tree's height
h.
938. Range Sum of BST
Easy·
2 Approachesclick to switch
1
DFS (Recursive)
O(n)
O(h)
2
DFS (Iterative)
O(n)
O(h)
FIG. RANGE SUM OF BST● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
recvisits each of thennodes at most once, pruning subtrees whose values fall entirely outside[low, high].- Space
- O(h)
- The recursion call stack grows one frame per level, up to the tree height
h.
510. Inorder Successor in BST II
Medium·
1
Parent Pointers
O(h)
O(1)
FIG. INORDER SUCCESSOR IN BST II● INTERACTIVE
visualization loads as you reach it
- Time
- O(h)
- Case 1 descends to the right subtree's leftmost node; case 2 climbs
p.parenttoward an ancestor. Both are bounded by the tree's heighth. - Space
- O(1)
- Only the pointer variable
pis tracked; no recursion or auxiliary structure.