← All Patterns

Pattern Recognition Drill

#34

Easy Trees

The Problem

Insert a value into a binary search tree.

What approach would you use?

Think about it before scrolling down.

BST insert

Key Signals

Tree Recursion

Compare value with node, go left or right. When you hit None, create the new node. O(h) time.

Common Trap

Don't forget to return the modified subtree root (or assign node.left/right = recursive call).

← #33 #35 →