A bubble sort, or sinking sort, is an algorithm that sorts lists into order by working within the list to swap and compare items. The process may take place several times before a list is in proper order. The sort gets its name from the small elements that continuously rise to the top of the list like bubbles in a drink. It is used most often to bring order to small lists.
The bubble sort works methodically, starting from the top of the list. It will start by comparing the first element to the second and switch them if necessary. Then it will continue down the list and make a swap again when it finds something out of order. Every time the algorithm makes a swap, the process will be started again from either the top or the bottom of the list.
Bubble sorts are from the comparison group of sorting algorithms. This type of algorithm works two elements at a time, determining on a pair-by-pair basis which of two values is higher or if they are equal. This kind of sort can provide a limited view of a data set, but it can also make it easier to fine tune elements of that set. Other algorithm types in the comparison group include the quick, merge, cocktail, and cycle sorts.
Another simple comparison sort algorithm called insertion point is believed to function more efficiently, while being built on a similarly simple concept. Rather than the items being reordered from the top, they are inserted in correct order relative to each other until the whole set is correctly ordered. In many instances, this sort has come to replace the bubble sort in both educational curricula and common use.
Though the bubble sort algorithm is easy to use and understand, it tends to be practical only for small lists. The speed and efficiency decline with a rise in the number of items on the list. Many programmers also find it difficult to use this relatively old method with newer computer systems as it was created before these more efficient machines existed.
There are some methods that can be used to increase the efficiency of the bubble sort. The most effective appears to be a method where the algorithm the works more smoothly if the largest elements of the list are placed early in the process. By having this base in place, it can take much fewer passes to finish ordering the rest of the list. This method of ordering can be written into the algorithm code.