Select the Sorting Algorithms that are stable. (A) Quick Sort (B) Bubble Sort…
2024
Select the Sorting Algorithms that are stable.
(A) Quick Sort
(B) Bubble Sort
(C) Insertion Sort
(D) Merge Sort
(E) Shell Sort
Choose the correct answer from the options given below:
- A.
(A), (B), (C) and (E) Only
- B.
(A), (D) and (E) Only
- C.
(B) and (C) Only
- D.
(B), (C) and (E) Only.
Attempted by 233 students.
Show answer & explanation
Correct answer: C
Definition: A sorting algorithm is stable if it preserves the relative order of records with equal keys.
Quick Sort: Typically unstable in common in-place implementations because partitioning can change the relative order of equal elements.
Bubble Sort: Stable, because it only swaps adjacent elements and equal elements retain their relative order.
Insertion Sort: Stable, because elements are inserted without changing the order of equal keys.
Merge Sort: Generally stable in its standard merge implementation because merging preserves the order of equal elements from the input runs. (Some implementations can be made unstable, but the canonical algorithm is stable.)
Shell Sort: Unstable, because its gap-based element moves can change the relative order of equal keys.
Conclusion: The stable sorting algorithms among those listed are Bubble Sort, Insertion Sort, and Merge Sort (assuming the standard stable merge implementation).
Note: If an answer key marks only Bubble Sort and Insertion Sort as stable, it is omitting Merge Sort, which is also stable in its usual implementation.
A video solution is available for this question — log in and enroll to watch it.