GATE Computer ScienceModerateGATE CS (PYQ pattern)

A binary tree is serialised in preorder with # for a null child: A B D # # E G # # # C # F # #. What is its inorder traversal and its height (single node = 0)?

  1. A. D G E B F C A; height 3
  2. B. D B G E A C F; height 4
  3. C. A B D E G C F; height 2
  4. D. D B G E A C F; height 3

Correct answer: D. D B G E A C F; height 3

Parsing: A has left subtree B(D, E(G, -)) and right subtree C(-, F). Inorder = D B G E A C F; the longest path A-B-E-G has 3 edges.

More Programming and Data Structures (GATE) questions

Exams that ask this topic