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

落爺英雄遲暮 提交于 2019-12-03 07:30:44

问题


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


回答1:


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:

  • Nonrecursive algorithms for reconstructing a binary tree from its traversals (paper)
  • reconstructing a tree from its preorder and postorder lists (SO question)


来源:https://stackoverflow.com/questions/1558032/prove-that-binary-trees-with-the-same-inorder-and-preorder-traversals-are-identi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!