Zigzag Traversal

An interactive, step-by-step visualisation of Zigzag Traversal.

Category
Trees
Time complexity
O(n)
Space complexity
O(n)

Pseudocode

level order, but reverse every other level

Reference implementation

# level order, reverse alternating levels
if not left_to_right: level.reverse()
out.extend(level)

Open the interactive Zigzag Traversal visualisation →