Construction of Binary Tree From Inorder and Preorder/Postorder Traversal Fully Explained
After finding a lot in books and Internet I found this easy method on how to create B.Tree from studying following data
Learn more »
a) - INORDER Traversal
-POSTORDER Traversal
OR
b) -INORDER Traversal
-PREORDER Traversal
We usually get Questions like :-
Create Binery tree from following tree Traversals
1) Inorder: E A C K F H D B G
Preorder: F A E K C D H G B
2) INORDER: D J H B E A F I C G
POSTORDER: J H D E B I F G C A
HERE the most important think to ALWAYS remember is :-
- In PREorder FIRST element is ROOT of the tree
- In POSTorder LAST element is ROOT of the tree
I hope you got it :P
i.e considering 1) Question
1) Inorder: E A C K F H D B G
Preorder: F A E K C D H G B
Considering 2) Question
2) INORDER: D J H B E A F I C G
POSTORDER: J H D E B I F G C A
* BLACK highlighted letters are roots
** RED highlighted letters will go to LEFT SUB TREE of Root
***GREEN highlighted letters will go to RIGHT SUB TREE of Root
Let us Start with Question 1)
Step 1)
Now as we know which one is Root So...
F
/ \
( E A C K) (H D B G)
Step 2)
Now FOR LEFT SUB TREE we have
E A C K from Inorder and same letters from Preorder A E K C
i.e Inorder E A C K
Preorder A E K C
now have found Root again so now tree is
F
/ \
A (H D B G)
/ \
E ( C K )
Step 3)
Now letters are
Inorder C K
Preorder K C
So now tree is
F
/ \
A (H D B G)
/ \
E K
/
C
Same procedure can be done on Right Sub tree Of root F
For Postorder we have to find Root as the last element in traversal....
For UPDATED Info VISIT
![[Image]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOYV3gv2z4Y2XHaKgtaFQqtp8tQv8N9WDq9vSgnPjxQV3RWVqWlBLKZ8fm-_wAsydesMGMbIiDOC7CPM7bHnLzMykSvKLJCw12wERb4X9N4ac4sNCYbHRS38NrLgh8QixaTfBBh33QUiU/s320/twitter.png)
![[Image]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq_Y6UTTOpjBjTOFD3F0HzGDazYEZYt6mcqV1V3Fu83F3hoLSMNccvVSA091xFd12pCuDunhlcLRORLY-0p87cnOEEo5lhT6E_V1nSkgd3NFNFd4CXnb904fFTnrT3sQOk280NTgeT2PM/s320/stumbleupon.png)
![[Image]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8-PRVD0_ilfe1o7yINUflbvhi3Zi-E_3nymhb91F8asEbbgM9LLIrHKl_ek8zYN-rIC5xDe88eSd5X84n9nX4k-KSZnAel_kyjC3_M8x8nvh9kSWuCem_SGIilF80G-RAF_5c_XveFRI/s320/facebook.png)
![[Image]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgASqt4SJgdYSu9j-GliS5rs5WiJQTT3QVujwA5cPS7fFh3zlIm3Tbyv_4PwVVkwzUDgfUybNAk07qVbKlcVFhXSe0VJYN1MQt3YgZhN4cbq-dYAqpYuW3fG1bBGaqIS3i11N59pC42CA/s320/rss.png)
![[Image]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxeLbuHpJcy2CM_w-PT7NrP6qvGGwOKCwVC4f-m3oo6ZemZpxxCEwcYPmJDTgoD5vEXu1oHcImR1hFWnKn02fBdNjWYiRAD9T8W9L17LpyIVTvrxhZZhK-Sql9Klk1mK3XtaUWj5h6OAQ/s320/technorati.png)