0

Can you help to explain the logic of how to do draw the original binary tree based on traversal results? I know pre-order and in-order traversal, but I can't figure out where to start with this question. Many thanks in advance!

A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) 
And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. 
Can you draw the tree structure? 
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user3735871
  • 527
  • 2
  • 14
  • 31

1 Answers1

0

You have to combine both informations. For a start:

Pre-order starts with root => A. From in-order you can see which nodes belong to the left and right subtree from A:

left - B,H,I,D

right - C,F,E,K,G,J

From pre-order you can see: left child of A is B. From in-order you can see which nodes belong to left and right subtree of B:

left - none

right - H,I,D

continue...

cbg
  • 68
  • 3