StreakPeaked· Practice

ExamsGATETechnical

Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE? I. Quicksort runs in Θ(n²) time II. Bubblesort runs in Θ(n²) time III. Mergesort runs in Θ(n) time IV. Insertion sort runs in Θ(n) time

  1. (A) I and II only
  2. (B) I and III only
  3. (C) II and IV only
  4. (D) I and IV only

Correct answer: (D) I and IV only

Solution

Quicksort has a worst-case time complexity of Θ(n²) when the input is already sorted, as it may repeatedly choose poor pivot elements. Insertion sort, however, is efficient for already sorted data, operating in Θ(n) time as it only requires a single pass through the list to confirm order.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →