## You are here

Homestable sorting algorithm

## Primary tabs

# stable sorting algorithm

A *stable sorting algorithm* is any sorting algorithm that preserves the relative ordering of items with equal values. For instance, consider a list of ordered pairs

$\displaystyle L:=\left\{(A,3),(B,5),(C,2),(D,5),(E,4)\right\}.$ |

If a stable sorting algorithm sorts $L$ on the second value in each pair using the $\leq$ relation, then the result is *guaranteed* to be
$\left\{(C,2),(A,3),(E,4),(B,5),(D,5)\right\}$. However, if an algorithm is not stable, then it is possible that $(D,5)$ may come before $(B,5)$ in the sorted output.

Some examples of stable sorting algorithms are bubblesort and mergesort (although the stability of mergesort is dependent upon how it is implemented). Some examples of unstable sorting algorithms are heapsort and quicksort (quicksort could be made stable, but then it wouldn’t be quick any more). Stability is a useful property when the total ordering relation is dependent upon initial position. Using a stable sorting algorithm means that sorting by ascending position for equal keys is built-in, and need not be implemented explicitly in the comparison operator.

## Mathematics Subject Classification

68P10*no label found*

- Forums
- Planetary Bugs
- HS/Secondary
- University/Tertiary
- Graduate/Advanced
- Industry/Practice
- Research Topics
- LaTeX help
- Math Comptetitions
- Math History
- Math Humor
- PlanetMath Comments
- PlanetMath System Updates and News
- PlanetMath help
- PlanetMath.ORG
- Strategic Communications Development
- The Math Pub
- Testing messages (ignore)

- Other useful stuff

## Recent Activity

new question: Prove that for any sets A, B, and C, An(BUC)=(AnB)U(AnC) by St_Louis

Apr 20

new image: information-theoretic-distributed-measurement-dds.png by rspuzio

new image: information-theoretic-distributed-measurement-4.2 by rspuzio

new image: information-theoretic-distributed-measurement-4.1 by rspuzio

new image: information-theoretic-distributed-measurement-3.2 by rspuzio

new image: information-theoretic-distributed-measurement-3.1 by rspuzio

new image: information-theoretic-distributed-measurement-2.1 by rspuzio

Apr 19

new collection: On the Information-Theoretic Structure of Distributed Measurements by rspuzio

Apr 15

new question: Prove a formula is part of the Gentzen System by LadyAnne

Mar 30

new question: A problem about Euler's totient function by mbhatia

## Corrections

rendering by CWoo ✓

stable algorithm? by Mathprof ✓

suppress link by Mathprof ✓