Question
The number of elements that can be sorted in time using heap sort is
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 elements using heap sort.
- Building a binary heap of elements takes time.
- Performing extract-min (or delete-max) operations takes time.
Therefore, the total time to sort elements using heap sort is . We are given that the running time must be :
Let us test :
Multiplying by :
This matches the required time . Hence, the number of elements that can be sorted is .
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.