AlgoScope

Preorder Traversal

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

Tree algorithms, algorithm, beginner
Visiting 50, number 1 of 7. The order so far is 50.20304050607080current
Visiting 50, number 1 of 7. The order so far is 50.20304050607080current

Tree Traversals: Preorder, node before subtrees

Decision, step 2 of 9

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

How tree traversals works

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(h)

Leads to

Topics that need this one first.

Taught by the same lesson

Tree Traversals covers these too, in the same run.