The worst case running times of Insertion sort , Merge sort and Quick sort, respectively are:
View worked solution
Answer: D
To find the worst-case running times of the three sorting algorithms, we analyze each individually:
- Insertion Sort: In the worst case (when the input array is sorted in reverse order), each element must be compared with and shifted past all previously sorted elements. The total number of comparisons is:
- Merge Sort: Merge sort is a divide-and-conquer algorithm that always divides the array into two equal halves, sorts them recursively, and merges them. Its recurrence relation in all cases (best, average, and worst) is: By Master's Theorem, this evaluates to .
- Quick Sort: In the worst case (e.g., when the array is already sorted or reverse-sorted, and the first or last element is chosen as the pivot), the partition step produces one subproblem of size and another of size . The recurrence relation is: This solves to .
Thus, the worst-case running times are , , and , respectively.
Free practice · Your answers on this page are not saved.
