AlgoScope

Preorder Traversal

AlgorithmbeginnerTree Traversals

Write the node down first, then walk its left subtree and then its right.

Decision · step 2 of 9Tree Traversals: Preorder, node before subtrees
20304050✓607080current

50 is the root, and preorder writes a node down before going anywhere.

Open in the player →or start at step 2

What you will see

Focus descends; each node is stamped in the output row the moment it is first reached.

How tree traversals works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(h)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Nodes announce value, left child and right child; each step announces the comparison and the direction taken or the structural change.

Reduced motion: Focus jumps node to node with a static ring; rotations become a crossfade between the two layouts.

Leads to

Topics that need this one first.