GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 50, 30, 70, 20, 40, 60, 80, 10, 25, 35, 45, 55, 65, 75, 85, 5, 12, 22, 27, 90 are inserted in this order into an empty BST (root at depth 0). What are its internal path length (sum of the depths of the 20 nodes) and its external path length (sum of the depths of the 21 NULL child links, a NULL link counted one level below its parent)?

  1. A. 54 and 94
  2. B. 54 and 74
  3. C. 54 and 75
  4. D. 74 and 94

Correct answer: A. 54 and 94

Depths: 50 at 0; 30, 70 at 1; 20, 40, 60, 80 at 2; 10, 25, 35, 45, 55, 65, 75, 85 at 3; 5, 12, 22, 27, 90 at 4. Internal path length = 0 + 2 + 8 + 24 + 20 = 54. For any binary tree with n nodes, E = I + 2n, so E = 54 + 40 = 94.

More Programming and Data Structures (GATE) questions

Exams that ask this topic