GATE / CS ARCHIVE

GATE CSE 2016 SET 1 / QUESTION 13

GATE CSE 2016 Set 1 Q13

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

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

Searching, Sorting & Selection

Question 13, GATE 2016: Select the worst-case running times of insertion sort, merge sort, and quicksort, in that order. A: Θ(n log n), Θ(n log n), Θ(n^2). B: Θ(n^2), Θ(n^2), Θ(n log n). C: Θ(n^2), Θ(n log n), Θ(n log n). D: Θ(n^2), Θ(n log n), Θ(n^2).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Insertion sort may shift Θ(n) elements on each of n insertions, giving Θ(n²). Merge sort uses Θ(n) work across each of Θ(log n) levels, giving Θ(n log n). Quicksort’s most unbalanced partitions give n+(n−1)+...+1=Θ(n²). Thus D.

For reverse-sorted input, insertion sort shifts 1+2+...+(n−1) elements. Merge sort's balanced divide-and-conquer recurrence T(n)=2T(n/2)+Θ(n) yields Θ(n log n) regardless of initial order. Quicksort can repeatedly choose an extreme pivot, leaving subproblems of sizes 0 and n−1, so its recurrence becomes T(n)=T(n−1)+Θ(n). Its average-case or expected randomized Θ(n log n) bound must not be substituted for this requested worst-case bound.

Original paper, page 7 · Answer key