AlgoScope

Zigzag Level Order

Level order with the reading direction flipped on every level.

Tree algorithms, algorithm, intermediate
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: Zigzag level order

Decision, step 2 of 9

50 is the root, and level order starts at the top.

How tree traversals works

Cost

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

A variant of

Taught by the same lesson

Tree Traversals covers these too, in the same run.