Question
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Official answer and solution
- Official answer
- D
- From
- Official GATE 2016 answer key
Solution
Recall the asymptotic worst-case time complexities of fundamental comparison-based sorting algorithms.
Examine the worst-case time complexity of each algorithm:
- Insertion Sort: In the worst case (reverse sorted input), each element is compared with and shifts all preceding elements. Total comparisons .
- Merge Sort: Divides the list into two halves () and merges them in time. By the Master Theorem, in all cases (worst, average, and best).
- Quick Sort: In the worst case (e.g. partition produces highly unbalanced subproblems of sizes and ), the recurrence is .
Therefore, the worst-case running times are , , and , respectively.
D
Stating for Quicksort, which is its average-case running time, rather than its worst-case running time .
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2016 Computer Science and Information Technology (CS) Session 1
- Question
- 23 of 65, printed as CS Q.13
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.