Skip to content
StackDecode
TreesExplained

Tree Flattening

Rewire a tree into a right-leaning linked list in preorder.

Time

O(n)

Extra space

O(1)

Use it for

Flatten to list in place.

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.