Binary tree traversal - Preorder,Inorder ,postorder - Data Structure

Q.  Data Structure: Preorder and in order of a tree is give

Preorder ----- A B D H E C F I G J K
Inorder -------- D H B E A I F C J G K

What will be the postorder?

- Published on 19 Oct 15

a. H D E B I F J K G C A
b. H D E B F I J K G C A
c. H D E B I F J K CG A
d. None of the above.

ANSWER: H D E B I F J K G C A
 

    Discussion

  • Nihal   -Posted on 01 Apr 16
    In the given question preorder and inorder is given. In preorder traversal, first node will be the first node. So ‘A’ is the root node. From given inorder sequence D, H, B, E are the nodes of left subtree and I, F, C, J, G, K are the nodes of right subtree.

    pre in order
    Again process the left subtree and right subtree as above.

    The final binary will be as follows:
    binary search traversal

    The post order traversal of this binary tree will be:
    H D E B I F J K G C A

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)