GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 50, 30, 70, 20, 40, 60, 80, 10, 35, 45, 65, 85, 5, 15, 32, 38, 90 are inserted in this order into an empty BST (root at depth 0). Number the positions of each level as in a heap (root 1, children of p at 2p and 2p + 1), and define the width of a level as (largest position - smallest position + 1), counting the empty places in between. What is the maximum width and the depth at which it first occurs?

  1. A. 5 at depth 3
  2. B. 16 at depth 4
  3. C. 8 at depth 3
  4. D. 16 at depth 3

Correct answer: B. 16 at depth 4

Positions per level (depth 3: 10 at 8, 35 at 10, 45 at 11, 65 at 13, 85 at 15; depth 4: 5 at 16, 15 at 17, 32 at 20, 38 at 21, 90 at 31). Depth 3 spans 8 to 15, width 8; depth 4 spans 16 to 31, width 16. Counting only the nodes present gives the maximum 5 at depth 3, which is a different measure.

More Programming and Data Structures (GATE) questions

Exams that ask this topic