Skip to content
Official PYQ · 1998

GATE CS 1998 Q1.22 — Searching, Sorting, Hashing

Explain with AI

Give the correct matching for the following pairs: (A)O(log⁡n)(P)Selection(B)O(n)(Q)Insertion sort(C)O(nlog⁡n)(R)Binary search(D)O(n2)(S)Merge sort\begin{array}{|ll|ll|}\hline \text{(A)} & \text{$O (\log n)$} & \text{(P)} & \text{Selection} \\ \hline \text{(B)} & \text{$O (n)$} & \text{(Q)}& \text{Insertion sort} \\ \hline \text{(C)}& \text{$O (n \log n)$} & \text{(R)} & \text{Binary search} \\ \hline \text{(D)} & \text{$O (n^2)$} &\text{(S)} & \text{Merge sort} \\ \hline \end{array}

Choose one option
View worked solution

Answer: B

We can determine the correct matching by analyzing the worst-case time complexity of each algorithm:

  • Binary Search (R): A search algorithm on a sorted array that halves the search space at each step. Its time complexity is governed by the recurrence T(n)=T(n/2)+O(1)T(n) = T(n/2) + O(1), which yields O(log⁡n)O(\log n).
    Matching: A → R\text{Matching: A } \rightarrow \text{ R}
  • Selection (P): The selection problem (finding the kk-th smallest element in an unsorted array of size nn) can be solved in linear time O(n)O(n) using the Median-of-Medians algorithm (or QuickSelect on average).
    Matching: B → P\text{Matching: B } \rightarrow \text{ P}
  • Merge Sort (S): A divide-and-conquer sorting algorithm with the recurrence T(n)=2T(n/2)+O(n)T(n) = 2T(n/2) + O(n). Its worst-case, average-case, and best-case time complexity is O(nlog⁡n)O(n \log n).
    Matching: C → S\text{Matching: C } \rightarrow \text{ S}
  • Insertion Sort (Q): A comparison-based sorting algorithm. In the worst case (e.g., when the input array is sorted in reverse order), it requires O(n2)O(n^2) comparisons and shifts.
    Matching: D → Q\text{Matching: D } \rightarrow \text{ Q}

Combining these matches, we get: A-R, B-P, C-S, D-Q, which corresponds to Option B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions