Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q13 — Searching, Sorting, Hashing

Explain with AI

The worst case running times of Insertion sort , Merge sort and Quick sort, respectively are:

Choose one option
View worked solution

Answer: D

To find the worst-case running times of the three sorting algorithms, we analyze each individually:

  1. Insertion Sort: In the worst case (when the input array is sorted in reverse order), each element must be compared with and shifted past all previously sorted elements. The total number of comparisons is: 1+2+3+⋯+(n−1)=n(n−1)2=Θ(n2)1 + 2 + 3 + \dots + (n-1) = \frac{n(n-1)}{2} = \Theta(n^2)
  2. Merge Sort: Merge sort is a divide-and-conquer algorithm that always divides the array into two equal halves, sorts them recursively, and merges them. Its recurrence relation in all cases (best, average, and worst) is: T(n)=2T(n/2)+Θ(n)T(n) = 2T(n/2) + \Theta(n) By Master's Theorem, this evaluates to Θ(nlog⁡n)\Theta(n \log n).
  3. Quick Sort: In the worst case (e.g., when the array is already sorted or reverse-sorted, and the first or last element is chosen as the pivot), the partition step produces one subproblem of size 00 and another of size n−1n-1. The recurrence relation is: T(n)=T(n−1)+Θ(n)T(n) = T(n-1) + \Theta(n) This solves to Θ(n2)\Theta(n^2).

Thus, the worst-case running times are Θ(n2)\Theta(n^2), Θ(nlog⁡n)\Theta(n \log n), and Θ(n2)\Theta(n^2), respectively.

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

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