UGC-NET Sep 2013 · Trees

MCQ · 2 marks · Problem PROG-DSTR-0013

Consider the In-order and Post-order traversals of a tree as given below: In-order: j e n k o p b f a c l g m d h i Post-order: j n o p k e f b c l m g h I d a The Pre-order traversal of the tree shall be
  1. A
    a b f e j k n o p c d g l m h i
  2. B
    a b c d e f j k n o p g l m h i
  3. C
    a b e j k n o p f c d g l m h i
  4. D
    j e n o p k f b c l m g h I d a

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionThe traversals are of a general (ordered) tree, where inorder means: first subtree in inorder, then the root, then the remaining subtrees in inorder. The last node in postorder, a, is the root. In the inorder, a splits the nodes into the first subtree \(\{j,e,n,k,o,p,b,f\}\) and the rest \(\{c,l,g,m,d,h,i\}\). Repeating this on each part gives the children lists\[a:(b,c,d),\ b:(e,f),\ e:(j,k),\ k:(n,o,p),\ d:(g,h,i),\ g:(l,m).\]Check: postorder of this tree is j n o p k e f b c l m g h i d a, as given. Preorder (root, then children left to right):\[a\ b\ e\ j\ k\ n\ o\ p\ f\ c\ d\ g\ l\ m\ h\ i.\]Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com