Skip to content
StackDecode
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

  1. Start at the root.
  2. If the key equals the target, found. If the target is smaller, go left; if larger, go right.
  3. If you fall off the tree the key is not there.
  4. Each step discards a whole subtree: O(height).

Watch it run

Loading animation…