Skip to content
StackDecode
TreesExplained

Construct Tree from Traversals

Preorder gives roots; inorder splits left from right.

Time

O(n)

Extra space

O(n)

Use it for

Rebuilding a tree from two orders.

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.