-1

can someone tell what is easy way to Traverse, if pre order is given and you have to write post and pre order ? e.g if in order is EACKFHDBG have to traverse in pre and post order?

Bibi Tahira
  • 1,082
  • 5
  • 15
  • 39

1 Answers1

1

Just one of the traversals in not sufficient to construct a tree. It will lead to construct many possible trees.

We would need the in-order and one of pre-order/post-order/ level-order together to construct a binary tree. Refer http://www.geeksforgeeks.org/if-you-are-given-two-traversal-sequences-can-you-construct-the-binary-tree/

Example:- in-order and pre-order are given we can print post-order. Refer http://www.geeksforgeeks.org/print-postorder-from-given-inorder-and-preorder-traversals/

Some other data along with in-order can also help in constructin unique binary tree and hence can be used to derive the other traversals. Refer http://www.quora.com/Given-an-in-order-traversal-of-a-special-binary-tree-having-property-that-the-node-is-always-greater-than-its-left-and-right-child-How-can-we-reconstruct-the-tree-efficiently

Aditya Guru
  • 646
  • 2
  • 10
  • 18