TreesAnimated
BST Insertion
Walk down as in search and attach a new leaf.
Time
O(h)
Extra space
O(1)
Use it for
Building ordered trees.
How it works
- Walk down exactly as in a search: smaller goes left, larger goes right.
- When you reach an empty spot, that is where the new key belongs.
- Attach it as a new leaf. No other node moves.
- Duplicates are ignored. O(height).
Watch it run
Loading animation…