Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prove that binary trees with the same inorder and preorder traversals are identical?

Does anybody know how to prove that if two binary trees have the same inorder and preorder traversals, then they are identical? (perhaps by showing that you can't have two different binary trees with identical inorder and preorder traversals)

Alternatively, show a case that would disprove this, or show why can't it be done?

(I'll admit, this is purely academic but it's not homework or anything. My instincts tell me that it's true, but I don't think I ever did any proofs on graphs.)

like image 946
erjiang Avatar asked Oct 13 '09 03:10

erjiang


People also ask

Can inorder and preorder traversal be the same?

In general, the inorder traversal is equivalent to the postorder traversal if there are only left children, and the inorder traversal is equivalent to the preorder traversal if there are only right children. Save this answer.

What is inorder and preorder traversal of a binary tree?

For Inorder, you traverse from the left subtree to the root then to the right subtree. For Preorder, you traverse from the root to the left subtree then to the right subtree. For Post order, you traverse from the left subtree to the right subtree then to the root.

Can any binary tree have Postorder and preorder traversal the same if yes give an example?

It is not possible to construct a general Binary Tree from preorder and postorder traversals (See this). But if know that the Binary Tree is Full, we can construct the tree without ambiguity. Let us understand this with the help of the following example.


1 Answers

The basic idea is how to reconstruct a binary tree by the given inorder and preorder traversals.

It's possible to reconstruct only one binary tree from the inorder and preorder traversals.

See:

like image 192
Nick Dandoulakis Avatar answered Sep 21 '22 18:09

Nick Dandoulakis