GATE Computer ScienceHardGATE CS

A binary tree is given in preorder with # for an empty child: 1 2 4 8 # # 9 # # 5 # 10 # # 3 6 # 11 # # 7 12 # # 13 # #. What is the maximum number of nodes on any single level (the width of the tree)?

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

Correct answer: A. 6

Parsing the preorder gives levels: {1}, {2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11, 12, 13}. The widest level is the last, with 6 nodes.

More Programming and Data Structures (GATE) questions

Exams that ask this topic