-
The central idea of bubbling ordering is to start at the head of the unordered sequence, compare them in pairs, swap positions according to size, and finally swap the largest (small) data element to the end of the unordered queue, thus becoming part of the ordered sequence; Continue the process next time until all the data elements are ordered. The core of the algorithm is to select the largest (smallest) data element in the remaining disordered sequence and put it at the end of the queue by comparing the positions in pairs at a time.
Bubbling sorting algorithm.
The operation is as follows:
1.Compare adjacent elements. If the first one is bigger (smaller) than the second, swap both of them.
2.Do the same work for each pair of adjacent elements, starting with the first pair and ending with the last pair. After this step is completed, the final element will be the largest (smallest) number.
3.Repeat the above steps for all elements, except for the last selected element (ordered).
4.Repeat the above steps each time for fewer and fewer elements (unordered elements) until there are no pairs of numbers to compare, and the sequence is finally ordered.
-
This ** shows the principle of bubble sorting through animation. I hope it will be helpful for everyone to understand the principle of bubble sorting. If you find it helpful, please like it, and it would be better if you followed this number. If you have any questions, you can also leave a message below.
-
Repeatedly visit the column of elements to be sorted, compare two adjacent elements in turn, and if their order (e.g. from largest to smallest, initial letter from a to z) is wrong, they swap beats. The work of visiting an element is repeated until there are no neighbors to swap, i.e. the element has been sorted.
Idea: Choose sorting, so that each number in the array is compared with the following number in turn, and if the number in front is greater than the number in the back, the position is exchanged. In other words, select Sort:
The first number is compared with the following number in turn, and the smallest number is first after the first comparison.
-
Brand model: Lenovo Legion Y9000P
System: Windows 11
The principle of the bubble sorting algorithm is as follows: compare adjacent elements, and if the first one is larger than the second, swap both of them; Do the same for each pair of adjacent elements, starting with the first pair and ending with the last pair, at which point the last element should be the largest number of pins; Repeat for all elements, except for the last one; Repeat the above steps for fewer and fewer elements each time until there are no pairs of numbers to compare.
Bubble sort is a simple algorithm for sorting holes 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 (e.g. from largest to smallest, first letter from z to a) is wrong. The work of visiting an element is repeated until there are no neighbors to swap, i.e. the element column has been sorted.
The name of this algorithm comes from the fact that the smaller elements slowly "float" to the top of the sequence (ascending or descending) through exchange, just as the bubbles of carbon dioxide in carbonated drinks eventually rise to the top, hence the name "bubbling order".
-
The principle of bubble sorting is: from left to right, adjacent elements are compared. Each round of comparison finds the largest or smallest one in the sequence. This number will pop up from the far right of the sequence.
Bubbling is the process of putting small elements in front or large elements in the back. A comparison is a comparison of two adjacent elements, and the exchange also takes place between these two elements. So, if the two elements are equal, they will not be exchanged again; If the two trouser elements are not adjacent to each other, then they will not be swapped even if they are adjacent to each other by swapping them in pairs.
Bubbling sorting
The basic idea of the selection sorting algorithm is to select the current smallest element for each position. The basic idea of choice sorting is based on two basic simple sorting methods: direct selection sorting and heap sorting. First of all, start from the first position of the drain to select all the elements, select the smallest of all elements to the position, and then select the second position, Huner can select the smallest among the remaining elements to this position.
The basic idea of quicksort is: through a sort algorithm, the elements of the sequence that need to be sorted are divided into two large blocks, wherein, one part of the elements must be less than or equal to the other part of the sequence elements, and then the elements of the two sequences after division are still implemented again according to this method, and the whole process of sorting realization can be called recursively.
The above content reference:Encyclopedia – Bubbling sorting
-
Bubbling sort is a simple and intuitive sorting algorithm that works by repeatedly traversing a sequence of things to be sorted, comparing two adjacent elements each time and swapping their positions if they are in the wrong order. Through multiple iterations and comparisons, the largest coarse element in the sequence to be sorted is gradually moved backward until the whole sequence is ordered. The name of the algorithm is that in each round of traversal, the largest element "bubbles" to the end.
Although the bubbling sorting algorithm is very simple, it has a high time complexity, and in the worst case, it requires $o(n 2)$ comparison and exchange operations, so it is less efficient when sorting large-scale data. However, the advantage of the bubble sorting algorithm is that it is easy to understand and suitable for the sorting of small-scale data, especially for the sorting of basically ordered data.
The implementation of the bubbling sorting algorithm is divided into two layers of loops, the outer loop controls the rounds of sorting, and the inner loop controls the comparison and exchange operations of adjacent elements in each round of sorting. You can determine whether there is an element swap in each round of sorting by adding a Boolean variable, and if not, it proves that the sequence is ordered and ends the sorting early. In addition, the sorting efficiency can be improved by narrowing down the range of the sequence to be sorted after each round of sorting.
In practical applications, although the bubble sorting algorithm has been replaced by a more efficient sorting algorithm, its ideas are still widely used. For example, in computer Yemingqiao graphics, the bubble sorting algorithm can be used to sort the graphic objects on the screen to achieve the occlusion relationship of the graphic objects. In addition, the bubble sorting algorithm can also be used to sort other data structures, such as linked lists, trees, etc.
In short, the bubble sorting algorithm is a simple and intuitive sorting algorithm, although the efficiency is low, but the implementation is simple and easy to understand, and it still has certain advantages in small-scale data sorting and basic ordered data sorting.
-
Bubbling sort is an out-of-order method of dressing up ().
a.Stable. b.Instability.
c.Sometimes stable, sometimes unstable.
d.None of the three options for the front collapse attack are correct.
Correct Answer: a
-
Bubble sort, the English of bubble sorting, is the most basic exchange sorting. It's called bubble sorting because each element can move little by little to one side of the array according to its size, just like a small bubble.
Bubbling sort is a simple sorting algorithm, and it is also a stable sorting algorithm. The implementation principle is to repeatedly scan the sequence to be sorted, compare each pair of adjacent elements, and swap when the pair of elements is not in the correct order. This process is repeated until there are no two adjacent elements that can be swapped, indicating that the sorting is complete.
In general, a sorting algorithm is said to be stable, which means that when there are the same elements in the sequence to be sorted, their positions will not change before and after sorting.
The principle of bubble sorting:
Only one number can be determined to be returned to each trip. That is, the first trip can only determine the number on the last digit, and the second trip can only return the number on the penultimate digit, and so on. If there are n numbers to sort, just return the n-1 number, that is, you need to perform the n-1 operation.
And "every trip" needs to start from the first position to compare the two adjacent numbers, put the larger number behind, and after the comparison, move one step backward to continue to compare the size relationship between the two adjacent two numbers below, and repeat this step until the last number has not been returned.
The central idea: This article takes "eavesdropping" as a clue, with the chronological order of rushing to the bookstore after school and reluctantly leaving at night, and the insertion of two scenes of hiding in many customers and reading on a rainy day, delicately and vividly depicting the unique feelings and complex tastes of "eavesdropping", and showing "my" love for reading and thirst for knowledge. >>>More
Warm current – 1Refers to hot springs. 2.Ocean currents flowing from low to high latitudes. The water temperature is higher than that of the area it is visiting. 3.The warmth and excitement felt in the heart of the metaphor.
This poem was written by Bai Juyi on the way to Hangzhou to serve as an assassin in the second year of Changqing. At that time, the politics of the imperial court were dim, the Niu and Li parties were fiercely contested, and the poet tasted the taste of the court officials and asked for foreign appointments. This poem reflects the author's relaxed mood after leaving the imperial court. >>>More
It is to let people know that they should cherish living well, and should not do those things that violate morality, so that everyone cherishes life, and Chainsaw also reflects some social problems and can cause people to reflect, although the old man's idea is right, but the approach is too extreme. Hoffman wanted to be in charge of the chainsaw door alone, and he hadn't been tested himself.
The text mainly describes the ascent process of the Chinese mountaineering team to the last 380 meters of Mount Everest in May 1960. In the first stage, the writing team members made full preparations and advanced to the top of the mountain. The second stage writes about the conquest of the famous "Second Steps". >>>More