Jump to content

Stable sorting algorithm

From Simple English Wikipedia, the free encyclopedia
Revision as of 21:49, 17 October 2020 by Gay Yong Hernandez (talk | changes)
Stability when sorting playing cards

A sorting algorithm is called stable if it preserves the order of elements with the same sorting key. Otherwise it is called unstable. Merge sort is an example of a stable sorting algorithm, quicksort is an example of an unstable sorting algorithm. Note that being stable has nothing to do with how difficult it is to do the sorting (known as complexity). Bubble sort is very easy to implement, but takes a very long time. It is a stable sorting algorithm. Heapsort is very efficient, but it is not stable.