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}\]
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