Home > Common Problem > body text

What does algorithm stability mean?

藏色散人
Release: 2020-06-30 09:21:58
Original
14921 people have browsed it

The stability of the algorithm refers to the fact that in a set of records to be sorted, if there are any two equal records R and S, and R is before S in the records to be sorted, if R is still before sorting S means that their front and back positions do not change before and after sorting, then the sorting algorithm is said to be stable.

What does algorithm stability mean?

Algorithm stability: In a set of records to be sorted, if there are any two equal records R and S, and in the records to be sorted, R is in Before S, if R is still before S after sorting, that is, their front and back positions do not change before and after sorting, then the sorting algorithm is said to be stable.

Stability of common sorting algorithms

Heap sort, quick sort, Hill sort, and direct selection sort are unstable sorting algorithms, while radix sort , bubble sort, direct insertion sort, half insertion sort, and merge sort are stable sorting algorithms.

First of all, everyone should know the stability of the sorting algorithm. In layman's terms, it can ensure that the order of the front and back positions of the two equal numbers before sorting is the same as the order of the front and back positions of the two after sorting. In simple formalization, if Ai = Aj, Ai is originally in front of the position, and Ai will still be in front of the position of Aj after sorting.

Secondly, let’s talk about the benefits of stability. If the sorting algorithm is stable, then sorting from one key and then sorting from another key, the result of the first key sorting can be used for the second key sorting. Radix sorting is like this, sorting by low bits first, then sorting by high bits. The order of elements with the same low bits will not change when the high bits are the same.

The above is the detailed content of What does algorithm stability mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!