GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 30

Inverting heapsort complexity

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2013 paper

GATE 2013, Q30 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 30, GATE 2013: How many elements can heapsort sort in Θ(log n) time? AΘ(1), BΘ(√log n), CΘ(log n/log log n), DΘ(log n).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Let m be the number of elements. Heapsort takes Θ(m log m). Choosing m=Θ(log n/log log n) gives log m=Θ(log log n), so m log m=Θ(log n). Hence C; m=Θ(log n) would require an extra log log n factor.

Use a new variable m for the input length, since n only describes the time budget. Heapsort costs Θ(m log m). Set L=log n. The candidate m=L/log L has log m=log L−log log L=Θ(log L), so m log m=Θ(L). Constant m is too small, and m=√L gives Θ(√L log L)=o(L). Setting m=L instead gives Θ(L log L), which is too large. Thus the inverse scale is log n/log log n.

Original paper, page 6 · Answer key