0

Click here for a sample tree image

When I am given an "inorder and preorder traversal", or "inorder and postorder traversal", how do I draw a tree that satisfies both traversals? In the most simplest way?

This question is probably not about converting traversals, but drawing while satisfying many rules of traversals.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Kam
  • 63
  • 11
  • From the preorder traversal, you can find the root. From the root and the inorder traversal, you can find the inorder traversals of the left and right subtrees. With those and the preorder traversal, you can find the preorder traversals of the left and right subtrees. With all that, you can recursively apply the process to determine the left and right subtrees. – user2357112 Jul 28 '17 at 22:43
  • You happen to have a BST there, but you can also generalise [the duplicate post](https://stackoverflow.com/questions/13167536/how-to-construct-bst-given-post-order-traversal) to deal with the case of being given 2 traversals, since the ordered property of a BST gives you the in-order traversal (see also [the answer by IVlad](https://stackoverflow.com/a/13168125/1711796)). – Bernhard Barker Jul 28 '17 at 22:59

0 Answers0