Workspace Tree Traversal
0d
Problem-solving patterns

Tree Traversal

Visit a node before, between, or after its child subtrees.

Recognition signal

A hierarchical result depends on parent-child order.

Method

Use preorder to emit roots first or postorder to combine child results.

Worked example

A root 5 with children 2 and 9 emits [2, 5, 9] in inorder.

Common mistake

A graph with shared links requires additional visit tracking.