GATE / CS ARCHIVE

GATE CSE 2014 SET 3 / QUESTION 39

GATE CSE 2014 Set 3 Q39

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2014 Set 3 paper

GATE 2014 Set 3, Q39 2 marks · NAT
Report issue

Binary Search & Balanced Trees

Question 39, GATE 2014: An unaugmented balanced BST T stores n numbers. There are m keys in the interval from L to H, whose sum must be computed. If the tightest upper bound is O(nᵃ logᵇ n + mᶜ logᵈ n), find a+10b+100c+1000d.
Tap to enlarge
Answer & solution

Official answer: 110

Step 1: Use the search ordering to locate the interval's first relevant key or its boundary in O(log n), since the tree is balanced. Step 2: Traverse the m matching keys in inorder while pruning subtrees wholly outside the interval. With a traversal stack, the total is O(log n+m), not m independent root-to-key searches costing O(m log n). Step 3: Match this to the displayed form: n⁰log¹n + m¹log⁰n, so (a,b,c,d)=(0,1,1,0). The requested encoding is 0+10+100+0=110. Subtree-sum augmentation was not specified and would change the range-sum method.

Original paper, page 61 · Answer key