GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. Its level-order traversal uses a queue: dequeue a node, then enqueue its non-null children. What is the maximum number of nodes simultaneously in the queue?

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

Correct answer: A. 6

The queue holds parts of two adjacent levels. Right after 40 is dequeued it contains 70, 90, 10, 25, 35, 45 (6 nodes), and later 35, 45, 5, 12, 22, 27 is again 6; it never exceeds 6.

More Programming and Data Structures (GATE) questions

Exams that ask this topic