Which of the following algorithms is not stable?
a) Merge Sort
b) Quick Sort
c) Bubble Sort
d) Insertion Sort
Answer:
b) Quick Sort
Explanation:
Quick Sort is not a stable sorting algorithm, meaning it does not guarantee that two equal elements will retain their relative order after sorting. The order of equal elements can change depending on the partitioning.
In contrast, Merge Sort, Bubble Sort, and Insertion Sort are stable algorithms that preserve the relative order of equal elements during sorting.
Stability is important in certain applications, such as when sorting a list of records based on multiple fields. For example, you may want to sort by one field while maintaining the order of another field that is already sorted.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers