Which of the following pairs gives the sorting algorithms with the minimum…
2013
Which of the following pairs gives the sorting algorithms with the minimum running-time complexity in the best case and the average case, respectively?
Answer: A. Insertion sort, Quick sort — Concept: Running-time comparisons must use the same input case for each algorithm. For a given case, the lower asymptotic order represents the smaller growth…
- A.
Insertion sort, Quick sort
- B.
Quick sort, Quick sort
- C.
Quick sort, Insertion sort
- D.
Insertion sort, Insertion sort
Attempted by 463 students.
Show answer & explanation
Correct answer: A
Concept: Running-time comparisons must use the same input case for each algorithm. For a given case, the lower asymptotic order represents the smaller growth rate as the input size increases.
Insertion sort has best-case time O(n) on an already sorted array and average-case time O(n2). Quick sort has best-case and average-case time O(n log n) under balanced or typical partitions.
Application
For the best-case slot, compare O(n) for Insertion sort with O(n log n) for Quick sort. The linear order O(n) is smaller, so Insertion sort belongs in this slot.
For the average-case slot, compare O(n2) for Insertion sort with O(n log n) for Quick sort. The order O(n log n) grows more slowly, so Quick sort belongs in this slot.
Cross-check
Case | Insertion sort | Quick sort | Lower order |
|---|---|---|---|
Best case | O(n) | O(n log n) | O(n) — Insertion sort |
Average case | O(n2) | O(n log n) | O(n log n) — Quick sort |
Cross-check: the comparison table places the lower order in each column: O(n) for the best case and O(n log n) for the average case.
Result: the required ordered pair is Insertion sort, Quick sort. The reversed pair Quick sort, Insertion sort assigns the algorithms to the opposite cases, which addresses why that alternative does not satisfy the stated order.
Explore the full course: Iocl Engineers Officers Grade A Paper 2