Sorting algorithm#Classification

A stable sorting algorithm is a sorting algorithm that preserves the order of the records whose sorting keys are equal.

For example, if a list sorted alphabetically persons files will be sorted according to the new birth, then remain at a stable sorting method, all persons with the same birth date in alphabetical order.

If you want to sort with an unstable sorting methods, such as quicksort, an array, while leaving the order of records with duplicate key among themselves unchanged, so you can help yourself so that you can store in an additional array, the initial positions of all the elements and in the case elements that are present with the same keys, it falls back. Normally one uses but instead mostly a stable sorting algorithm.

Stable and unstable sorting methods to sort a dataset equal if the sort key performs a comparison on the entire record and evaluate different data sets also unequal. A set of numbers or names as you can sort with a stable or unstable sorting algorithm, the result is always the same:

Stable or unstable sorting methods:

4 1    3 2    5 3    3 → 3    2 3    1 4    3 5 Stable or unstable sorting method (alphabetically ):

Carla Annette    Annette → Birgit    Birgit Carla However, when combining some names and numbers to one data record each and sorted only by a partial key, after about numbers, then there are several possibilities for the sequence with the same keys. A stable method chooses the order in which the original order of the names in maintaining the same keys, such as

Stable sorting method by numbers:

1 1 Anton Anton    4 1 Charles Paul    3 Otto Otto 3    5 → 3 Bernd Herbert    3 Herbert 4 Karl    8 Alfred 5 Bernd    1 8 Paul Alfred Unstable sorting algorithms by numbers:

1 1 Paul Anton Anton 1 1 1 Paul Anton    4 1 Karl Anton Paul 1 1 1 Paul Anton    Otto Otto 3 3 3 3 Herbert Herbert Otto 3    5 Bernd Herbert → 3 or 3 or 3 Otto Otto or 3 Herbert    3 Herbert 4 Karl Karl 4 4 4 Karl Karl    8 Alfred 5 Bernd Bernd 5 5 5 Bernd Bernd    Paul Alfred 1 8 8 8 Alfred Alfred Alfred 8 In unstable sorting Paul can stand before Otto Anton before or Herbert.

Examples

Stable sorting methods:

Unstable sorting algorithms:

413358
de