In: Computer Science
the following lists the nodes in a binary tree in two different orders:
Preorder : A B C D E F G H I J K L M
Inorder : C E D F B A H J I K G M L
Draw the binary tree
Answer:
In order to draw a binary tree from Preorder and Inorder traversals. We have to know some basics.
Given Preorder and Inorder traversals
First element in preorder is A. So A is root node. Search that element in Inorder.
From A -> Left we have ( C E D F B )
From A -> Right we have ( H J I K G M L)
Call recursively until you get the binary tree.
The Fina binary tree will be
Thank you. Please ask me if you hav any doubt and upvote my answer if you like it.