RK DSA Studio

Tree traversals

Compare inorder, preorder, postorder and level-order tree traversals with synchronized code, output and a 2D or 3D tree.

Remember: Depth-first traversals use a stack; level order uses a queue.

Example: Root 2 with children 1 and 3: inorder [1,2,3], preorder [2,1,3], postorder [1,3,2], level order [2,1,3].

Time: O(n). Auxiliary space: O(h) depth-first stack; O(w) breadth-first queue.

Complexities describe the underlying algorithm; tutorial snapshots and rendering can use additional resources.

The interactive workspace loads here when JavaScript is available. You can still browse the learning notes and links above without it.