Assume that the algorithms considered here sort the input sequences in…

2016

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^2)\) time

II. Bubblesort runs in \(Θ(n^2)\) 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

Attempted by 241 students.

Show answer & explanation

Correct answer: D

Answer: Statements I and IV are true; Statements II and III are false.

Reasoning:

  • Statement I (Quicksort runs in Θ(n²) time): True under the common classroom assumption that quicksort chooses a poor pivot deterministically (for example always choosing the first or last element). On an already sorted array that pivot choice leads to highly unbalanced partitions and the worst-case Θ(n²) behavior. If a randomized or more careful pivot selection is used, quicksort would instead run in Θ(n log n) on average, so pivot strategy matters.

  • Statement II (Bubblesort runs in Θ(n²) time): False for the usual optimized version of bubble sort that checks whether any swaps occurred during a pass and stops early if the array is already sorted; that version has Θ(n) best-case time on already sorted input. A strictly unoptimized bubble implementation that always does all passes would be Θ(n²), but the common algorithm taught includes the early-exit optimization.

  • Statement III (Mergesort runs in Θ(n) time): False. Mergesort performs divide-and-conquer merges that take Θ(n log n) time in all cases (best, average, and worst) because the divide depth is Θ(log n) and each level requires Θ(n) work.

  • Statement IV (Insertion sort runs in Θ(n) time): True. Insertion sort performs a single pass with no shifts when the input is already sorted, giving Θ(n) best-case time.

Summary: Under the standard assumptions (naive pivot selection for quicksort, optimized bubble sort with early exit), the true statements for an already sorted input are that quicksort can be Θ(n²) and insertion sort is Θ(n); mergesort is Θ(n log n) and bubble sort is Θ(n) in its optimized form.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir