What is mean by stable sorting algorithm?

What is mean by stable sorting algorithm?
| What is mean by stable sorting algorithm?

A. A sorting algorithm is stable if it doesn’t preserve the order of duplicate keys

B. A sorting algorithm is stable if it preserves the order of duplicate keys

C. A sorting algorithm is stable if it preserves the order of all keys

D. A sorting algorithm is stable if it preserves the order of non-duplicate keys

Please scroll down to see the correct answer and solution guide.

Right Answer is: B

SOLUTION

Concept

The stability of a sorting algorithm is concerned with how the algorithm treats equal (or repeated) elements.

A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input array to be sorted.

Some sorting algorithms are stable by nature like Insertion sort, Merge Sort, Bubble Sort, etc. And some sorting algorithms are not, like Heap Sort, Quick Sort, etc.