Skip to content
StackDecode
TreesExplained

Vertical Order Traversal

Group nodes by horizontal distance from the root.

Time

O(n log n)

Extra space

O(n)

Use it for

Column-wise views.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.