StreakPeaked· Practice

ExamsGATETechnical

Consider a binary tree T in which every node has either zero or two children. Let n > 0 be the number of nodes in T. Which ONE of the following is the number of nodes in T that have exactly two children?

  1. (n - 2) / 2
  2. (n - 1) / 2
  3. n / 2
  4. (n + 1) / 2

Correct answer: (n - 1) / 2

Solution

In a binary tree where every node has either zero or two children, the number of nodes with two children is always one less than the total number of leaf nodes. Since there are n nodes in total, the formula (n - 1) / 2 correctly represents the count of nodes with two children.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →