Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→Algorithm
(→Algorithm: optimize noting that each pass finds the maximum item) |
|||
Line 8:
The '''bubble sort''' is generally considered to be the simplest sorting algorithm. Because of its simplicity and ease of visualization, it is often taught in introductory computer science courses. Because of its abysmal performance, it is never used anywhere else.
The bubble sort works by passing sequentially over a list, comparing each value to the one immediately after it. If the first value is greater than the second, their positions are switched. Over a number of passes, at most equal to the number of elements in the list, all of the values drift into their correct positions. Because each pass finds the maximum item and puts it at the end, the portion of the list to be
This can be expressed in pseudocode as follows (assuming 1-based indexing):
|