Skip to content
DSA Visualizerpreview

Pre-order traversal

The node first, then its subtrees: the order you would copy a tree in.

O(n) time · O(height) for the recursion space

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

The tree built from 50, 30, 70, 20, 40, 60, 80. Visit every node pre-order.

Tree with 7 nodes; in order: 20, 30, 40, 50, 60, 70, 80. Visited so far: none.
  • compare
  • swap or write
  • settled

1 / 16

Speed

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