Question

The number of elements that can be sorted in Θ(log⁡n)\Theta(\log n) time using heap sort is

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2013 answer key

Solution

Express the running time of heapsort as a function of the number of elements k and solve for k such that the time is Theta(log n).

Suppose we sort kk elements using heap sort.

  1. Building a binary heap of kk elements takes O(k)O(k) time.
  2. Performing kk extract-min (or delete-max) operations takes k×O(log⁡k)=Θ(klog⁡k)k \times O(\log k) = \Theta(k \log k) time.

Therefore, the total time to sort kk elements using heap sort is Θ(klog⁡k)\Theta(k \log k). We are given that the running time must be Θ(log⁡n)\Theta(\log n):

klog⁡k=Θ(log⁡n)k \log k = \Theta(\log n)

Let us test k=Θ(log⁡nlog⁡log⁡n)k = \Theta\left(\dfrac{\log n}{\log \log n}\right):

log⁡k=log⁡(log⁡nlog⁡log⁡n)=log⁡log⁡n−log⁡log⁡log⁡n=Θ(log⁡log⁡n)\log k = \log\left(\dfrac{\log n}{\log \log n}\right) = \log \log n - \log \log \log n = \Theta(\log \log n)

Multiplying kk by log⁡k\log k:

klog⁡k=Θ(log⁡nlog⁡log⁡n)×Θ(log⁡log⁡n)=Θ(log⁡n)k \log k = \Theta\left(\dfrac{\log n}{\log \log n}\right) \times \Theta(\log \log n) = \Theta(\log n)

This matches the required time Θ(log⁡n)\Theta(\log n). Hence, the number of elements that can be sorted is Θ(log⁡nlog⁡log⁡n)\Theta\left(\dfrac{\log n}{\log \log n}\right).

Final answer

C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2013 Computer Science and Information Technology (CS)
Question
30 of 65, printed as CS Q.30
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.