The GATE Grind

GATE 2016 CS (CS2) – Question 23

Algorithms · Searching, Sorting and Hashing · 1 mark · Multiple choice

Algorithms sort in ascending order. On an already ascending input, which are true? I: Quicksort takes $\Theta(n^2)$. II: Bubblesort takes $\Theta(n^2)$. III: Mergesort takes $\Theta(n)$. IV: Insertion sort takes $\Theta(n)$.

  1. I and II only
  2. I and III only
  3. II and IV only
  4. I and IV only

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) I and IV only

Explanation

The keyed D assumes first/last-element-pivot quicksort and early-termination bubble sort. Quicksort then repeatedly splits into 0 and n−1, costing Θ(n²). Bubble sort stops after one no-swap pass. Ordinary mergesort is Θ(n log n), and insertion sort makes one comparison per new item, Θ(n). Thus I and IV under those conventions. The unspecified pivot and bubble-sort variant make the printed question implementation-dependent.

More Searching, Sorting and Hashing questions

All Searching, Sorting and Hashing questions →