GateAI
Recursion

GATE CSE 2014 Set 1 · Q12

NAT1 markMedium

Time

Consider a rooted nn node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly 4 nodes is O(nalog⁡bn)O(n^a \log^b n). Then the value of a+10ba + 10b is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 1

Recursion

To find the number of subtrees having exactly 4 nodes in an nn-node binary tree:

  1. We can perform a post-order (bottom-up) traversal of the tree.

  2. For each node, the size of the subtree rooted at that node can be computed in O(1)O(1) time:

    size(u)=1+size(left(u))+size(right(u))\text{size}(u) = 1 + \text{size}(\text{left}(u)) + \text{size}(\text{right}(u))
  3. Whenever size(u)==4\text{size}(u) == 4, we increment a count.

  4. Since post-order traversal visits each node in the binary tree exactly once and performs constant O(1)O(1) work per node, the overall time complexity is O(n)O(n).

Comparing O(n)O(n) with O(nalog⁡bn)O(n^a \log^b n):

a=1,b=0a = 1, \quad b = 0

Thus:

a+10b=1+10(0)=1a + 10b = 1 + 10(0) = 1

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Recursion previous year question is Q12 of the GATE CSE 2014 Set 1 paper. Find more GATE CSE PYQs on Recursion in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Recursion PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Recursion in GATE CSE

Recursion has 19 GATE CSE PYQs across 15 papers from 2011 to 2026. 2 of them are 1-mark NAT questions like this one, and it is the only one in GATE CSE 2014 Set 1.

How GATE tests Recursion

More from GATE CSE 2014 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 1 · Q12 · NAT

Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly 4 nodes is O(na logb n). Then the value of a + 10b is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.