If you are given two traversal sequences, can you construct the binary tree?
It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can be constructed, otherwise not.
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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
Recommended Posts:
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Construct Special Binary Tree from given Inorder traversal
- Construct the full k-ary tree from its preorder traversal
- Construct a special tree from given preorder traversal
- Construct the Rooted tree by using start and finish time of its DFS traversal
- Check if a binary tree is subtree of another binary tree using preorder traversal : Iterative
- Construct XOR tree by Given leaf nodes of Perfect Binary Tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Construct a Binary Search Tree from given postorder
- Construct a Binary Tree from Postorder and Inorder
- Construct Ancestor Matrix from a Given Binary Tree
- Construct Binary Tree from String with bracket representation
- Construct Binary Tree from given Parent Array representation
- Construct Binary Tree from Ancestor Matrix | Top Down Approach
- Construct Full Binary Tree from given preorder and postorder traversals

