Is selection sort stable?

Understand the Problem

The question is asking whether the selection sort algorithm maintains the relative order of records with equal keys (i.e., whether it is stable). A stable sorting algorithm preserves the original order of equal elements, and this question seeks to clarify if selection sort meets this criterion.

Answer

Selection sort is not stable

Selection sort is not stable

Answer for screen readers

Selection sort is not stable

More Information

Stability in sorting algorithms means that two equal elements maintain their relative order before and after sorting. In selection sort, this is not guaranteed because elements can be swapped regardless of their original positions.

Tips

A common mistake is to assume all simple sorting algorithms are stable. Always verify this property before applying a sorting algorithm where stability is important.

AI-generated content may contain errors. Please verify critical information

Thank you for voting!