GateAI
Binary Search Trees

GATE CSE 2014 Set 3 · Q39

NAT2 marksMedium

Time

Suppose we have a balanced binary search tree TT holding nn numbers. We are given two numbers LL and HH and wish to sum up all the numbers in TT that lie between LL and HH. Suppose there are mm such numbers in TT. If the tightest upper bound on the time to compute the sum is O(nalog⁡bn+mclog⁡dn)O(n^a \log^b n + m^c \log^d n), the value of a+10b+100c+1000da + 10b + 100c + 1000d is _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 110

Binary Search Trees

To find and sum all elements in a balanced Binary Search Tree within the range [L,H][L, H]:

  1. Locating the boundaries: Finding the starting node (the lowest common ancestor or the smallest element ≥L\ge L) takes O(log⁡n)O(\log n) time because the height of the balanced BST is O(log⁡n)O(\log n).

  2. Visiting the elements: Once the range is found, traversing and summing the mm matching nodes (for example, by an in-order traversal that prunes subtrees outside [L,H][L, H]) visits O(log⁡n+m)O(\log n + m) nodes in total, which takes O(log⁡n+m)O(\log n + m) time.

Thus, the tightest upper bound on time complexity is:

O(log⁡n+m)=O(n0log⁡1n+m1log⁡0n)O(\log n + m) = O(n^0 \log^1 n + m^1 \log^0 n)

Comparing with the expression O(nalog⁡bn+mclog⁡dn)O(n^a \log^b n + m^c \log^d n):

  • a=0a = 0

  • b=1b = 1

  • c=1c = 1

  • d=0d = 0

Calculating the required linear combination:

a+10b+100c+1000d=0+10(1)+100(1)+1000(0)=0+10+100+0=110a + 10b + 100c + 1000d = 0 + 10(1) + 100(1) + 1000(0) = 0 + 10 + 100 + 0 = 110

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 Binary Search Trees previous year question is Q39 of the GATE CSE 2014 Set 3 paper. Find more GATE CSE PYQs on Binary Search Trees 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 Binary Search Trees 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.

Binary Search Trees in GATE CSE

Binary Search Trees has 21 GATE CSE PYQs across 17 papers from 2011 to 2026. 3 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2014 Set 3.

How GATE tests Binary Search Trees

More from GATE CSE 2014 Set 3

Share this solution

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

GateAI solution cardGATE CSE 2014 Set 3 · Q39 · NAT

Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is O(na logb n + mc logd n), the value of a + 10b + 100c + 1000d 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.