TreesAnimated
Binary Search Tree Search
Go left or right by comparing with each node.
Time
O(h)
Extra space
O(1)
Use it for
Ordered lookups.
How it works
- Start at the root.
- If the key equals the target, found. If the target is smaller, go left; if larger, go right.
- If you fall off the tree the key is not there.
- Each step discards a whole subtree: O(height).
Watch it run
Loading animation…