Question
Match the algorithms with their time complexities:
| Algorithm | Time complexity |
|---|---|
| (P) Towers of Hanoi with disks | (i) |
| (Q) Binary search given sorted numbers | (ii) |
| (R) Heap sort given numbers at the worst case | (iii) |
| (S) Addition of two matrices | (iv) |
Official answer and solution
- Official answer
- C
- From
- Official GATE 2017 answer key
Solution
Identify the standard worst-case time complexities of the four algorithms.
Analyze each algorithm:
- (P) Towers of Hanoi with disks: The recurrence is , which gives . This matches (iii).
- (Q) Binary search on sorted numbers: Halves the search space at each comparison, giving recurrence , so . This matches (iv).
- (R) Heap sort on numbers (worst case): Building the heap takes , and each of the extractions takes heapify time, yielding a worst-case time complexity of . This matches (ii).
- (S) Addition of two matrices: Requires adding pairs of corresponding elements, taking time. This matches (i).
Combining the matches gives P (iii), Q (iv), R (ii), S (i), matching option C.
Final answer
C
Common trap
Confusing matrix addition (which is ) with standard matrix multiplication (which is ).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 2
- Question
- 3 of 65, printed as CS Q.3
- 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.