StreakPeaked· Practice

ExamsGATETechnical

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

  1. Θ(n log n), Θ(n log n), and Θ(n²)
  2. Θ(n²), Θ(n²), and Θ(n log n)
  3. Θ(n²), Θ(n log n), and Θ(n log n)
  4. Θ(n²), Θ(n log n), and Θ(n²)

Correct answer: Θ(n²), Θ(n log n), and Θ(n²)

Solution

Insertion sort has a worst-case running time of Θ(n²) due to its nested loops when the input is in reverse order. Merge sort consistently performs at Θ(n log n) because it divides the array and merges sorted subarrays regardless of the input order. Quick sort, while efficient on average, can degrade to Θ(n²) in the worst case when the pivot selection is poor, such as when the smallest or largest element is consistently chosen.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →