GATE Computer ScienceEasyGATE CS (PYQ pattern)

In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key equal to the sum of the keys of their children (a missing child counts as 0)?

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

Correct answer: C. 5

Check each internal node: 44 = 20 + 24, 20 = 12 + 8, 24 = 9 + 15, 9 = 4 + 5 and 15 = 0 + 15, so all five non-leaf nodes satisfy the property.

More Programming and Data Structures (GATE) questions

Exams that ask this topic