GATE / CS ARCHIVE

GATE CSE 2017 SET 2 / QUESTION 3

GATE CSE 2017 Set 2 Q3

Algorithms · Asymptotic Analysis & Recurrences · Full GATE CSE 2017 Set 2 paper

GATE 2017 Set 2, Q3 1 mark · MCQ
Report issue

Asymptotic Analysis & Recurrences

Question 3, GATE 2017: Match P:Towers of Hanoi with n disks; Q:binary search of n sorted numbers; R:worst-case heapsort of n numbers; S:addition of two n×n matrices. Complexities i:Θ(n²), ii:Θ(n log n), iii:Θ(2^n), iv:Θ(log n). Options (P,Q,R,S): A:(iii,iv,i,ii), B:(iv,iii,i,ii), C:(iii,iv,ii,i), D:(iv,iii,ii,i).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Hanoi moves n-1 disks away, moves the largest disk once, then moves n-1 disks back: T(n)=2T(n-1)+1=2n-1, so P→iii.

2. Binary search halves the candidate interval each time; after k comparisons about n/2k candidates remain. Reaching one requires Θ(log n) comparisons, so Q→iv.

3. Heapsort builds a heap in O(n) and performs n extractions costing O(log n) each in the worst case, giving Θ(n log n): R→ii. Matrix addition performs one addition at each of n² positions, giving S→i. Select C.

Original paper, page 2 · Answer key