GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 13

GATE CSE 2016 Set 2 Q13

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2016 Set 2 paper

GATE 2016 Set 2, Q13 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 13, GATE 2016: For ascending sorted input, assess: I quicksort is Θ(n²); II bubblesort is Θ(n²); III mergesort is Θ(n); IV insertion sort is Θ(n). A I,II only; B I,III only; C II,IV only; D I,IV only. The source supplies no implementation details.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Our answer: D under textbook implementation conventions

With first/last-element pivot selection, sorted input gives quicksort Θ(n²). An early-exit bubble sort detects no swaps after one pass and takes Θ(n), ordinary mergesort remains Θ(n log n), and insertion sort takes Θ(n). These conventions make I and IV true, D. The names alone do not determine these cases: a balanced/randomized-pivot quicksort need not be quadratic, unoptimized bubble sort can be quadratic, and adaptive mergesort can be linear. The official answer requires the stated implementation choices.

The quadratic quicksort recurrence is T(n)=T(n−1)+Θ(n), whose level costs add to Θ(n²). The insertion-sort best case makes one failed comparison per new item, hence linear work. Standard merging processes n elements at each of log n levels. These derivations explain the official convention rather than falsely treating algorithm names as complete implementations.

Original paper, page 28 · Answer key