Can two different binary trees have identical postorder sequ

Can two different binary trees have identical postorder sequences and also identical inorder sequences? Explain.

Solution

Actually, it is impossible to reconstruct only one binary tree from inorder and preorder traversals.

For post-order:

Reconstruct the tree in post-order is possible in BST.

The last element in the array can be a root that is, at pos n. we

have to find right-most element bigger than the root, and that\'s

root\'s first right-subtree. then we must find closest element to

the end of the array that can be smaller than root,that is the left

element.

let see one example,

consider an array [5,8,6,10,9]

as i mentioned above, the last element in the array 9 is a root.

and 6 is the right-most element smaller than 9

so that can be left sub tree.

9

/

/

6

then, 10 is the right-most element bigger than 9

9

/ \\

6 10

then the root is 6,here the right-most element smaller than 6 is 5,

then the tree is

9

/ \\

6 10

/

5

and then the right-most element bigger than 5 is 8

so the tree is,

9

/ \\

6 10

/ \\

5 8

Can two different binary trees have identical postorder sequences and also identical inorder sequences? Explain.SolutionActually, it is impossible to reconstruc
Can two different binary trees have identical postorder sequences and also identical inorder sequences? Explain.SolutionActually, it is impossible to reconstruc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site