GATE CS 2017 · Set-2 · Heap Sort & Non-Comparison Sorts

MCQ · 1 mark · Problem PROG-SORT-0026

Match the algorithms with their time complexities:\[\begin{array}{ll} \textbf{Algorithm} & \textbf{Time complexity} \\ \text{(P) Towers of Hanoi with } n \text{ disks} & \text{(i) } \Theta(n^2) \\ \text{(Q) Binary search given } n \text{ sorted numbers} & \text{(ii) } \Theta(n \log n) \\ \text{(R) Heap sort given } n \text{ numbers at the worst case} & \text{(iii) } \Theta(2^n) \\ \text{(S) Addition of two } n \times n \text{ matrices} & \text{(iv) } \Theta(\log n) \end{array}\]
  1. A
    P-(iii), Q-(iv), R-(i), S-(ii)
  2. B
    P-(iv), Q-(iii), R-(i), S-(ii)
  3. C
    P-(iii), Q-(iv), R-(ii), S-(i)
  4. D
    P-(iv), Q-(iii), R-(ii), S-(i)

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solution(P) Towers of Hanoi: \(T(n)=2T(n-1)+1\), so \(T(n)=2^n-1=\Theta(2^n)\): (iii).(Q) Binary search halves the range at each step: \(\Theta(\log n)\): (iv).(R) Heap sort in the worst case: \(n\) deletions from a heap, each \(O(\log n)\): \(\Theta(n\log n)\): (ii).(S) Adding two \(n\times n\) matrices touches each of the \(n^2\) entries once: \(\Theta(n^2)\): (i).Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com