← All Patterns

Pattern Recognition Drill

#35

Easy Trees

The Problem

Search for a value in a BST. Return the node or None.

What approach would you use?

Think about it before scrolling down.

BST search

Key Signals

Tree Recursion

Compare with root, recurse left or right. O(h) time — O(log n) for balanced, O(n) for skewed.

Common Trap

Iterative version is also fine and avoids stack overhead: while node: go left or right.

← #34 #36 →