erjiang
erjiang

Reputation: 45727

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.)

Upvotes: 11

Views: 9054

Answers (1)

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43130

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:

Upvotes: 5

Related Questions