The Wayback Machine - https://web.archive.org/web/20210417010712/https://www.geeksforgeeks.org/if-you-are-given-two-traversal-sequences-can-you-construct-the-binary-tree/
Skip to content
Related Articles

Related Articles

If you are given two traversal sequences, can you construct the binary tree?
  • Difficulty Level : Easy
  • Last Updated : 11 Apr, 2011
GeeksforGeeks - Summer Carnival Banner

It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can be constructed, otherwise not.

Mirror
Therefore, following combination can uniquely identify a tree.

Inorder and Preorder.
Inorder and Postorder.
Inorder and Level-order.

And following do not.

Postorder and Preorder.
Preorder and Level-order.
Postorder and Level-order.

For example, Preorder, Level-order and Postorder traversals are same for the trees given in above diagram.

Preorder Traversal = AB
Postorder Traversal = BA
Level-Order Traversal = AB

So, even if three of them (Pre, Post and Level) are given, the tree can not be constructed.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :