GATE Computer ScienceHardGATE CS (PYQ pattern)

A binary tree is stored in level order with null children written as _ : 1 2 3 4 _ 5 6 _ 7 _ _ 8 _ (a null child still consumes a slot only if its parent is present; children are assigned to non-null nodes in queue order, 2 per node). What is its postorder traversal?

  1. A. 1 2 4 7 3 5 6 8
  2. B. 1 3 6 8 5 2 4 7
  3. C. 1 2 3 4 5 6 7 8
  4. D. 7 4 2 5 8 6 3 1

Correct answer: D. 7 4 2 5 8 6 3 1

Children are assigned in queue order: 1 has (2, 3); 2 has (4, _); 3 has (5, 6); 4 has (_, 7); 5 has none; 6 has (8, _). The postorder is 7 4 2 5 8 6 3 1.

More Programming and Data Structures (GATE) questions

Exams that ask this topic