Home > Common Problem > body text

What does bubble sort mean?

藏色散人
Release: 2020-06-29 10:33:53
Original
5865 people have browsed it

Bubble sorting is a relatively simple sorting algorithm in the field of computer science. It repeatedly visits the column of elements to be sorted, compares two adjacent elements in turn, and swaps them if the order is wrong. , the work of visiting elements is repeated until no adjacent elements need to be exchanged, which means that the element column has been sorted.

What does bubble sort mean?

Bubble sort

When sorting a sequence to be sorted with N elements, A total of N-1 cycles are performed. In the k-th loop, the elements from the 1st to the N-kth are compared from front to back, and the two adjacent elements are compared each time. If the former element is greater than the latter element, the two exchange positions, otherwise they remain Position unchanged

Time complexity: O(N2)

Introduction:

Bubble Sort (Bubble Sort) is a simpler sort in the field of computer science algorithm.

It repeatedly visits the column of elements to be sorted, compares two adjacent elements in turn, and swaps them if the order (such as from large to small, first letter from Z to A) is wrong. The work of visiting elements is repeated until no adjacent elements need to be exchanged, which means that the element column has been sorted.

The name of this algorithm comes from the fact that smaller elements will slowly "float" to the top of the sequence through exchange (in ascending or descending order), just like the carbon dioxide bubbles in carbonated drinks will eventually float to the top. , hence the name "bubble sort".

The above is the detailed content of What does bubble sort 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