Skip to content
DSA Visualizerpreview

Binary search tree: insert

Each value walks down, left if smaller, right if not, until it finds an empty spot.

O(h) per insert (O(log n) balanced, O(n) worst) time · O(n) space

Values50, 30, 70, 20, 40, 60, 80, 35

Insert 50, 30, 70, 20, 40, 60, 80, 35 into an empty binary search tree.

Empty tree.
  • compare
  • swap or write
  • settled

1 / 23

Speed

Space play · ← → step · Home End jump · drag the strip to scrub