Bubble sort

The most inefficient of the sorting algorithms. While asymptotically equivalent to the other $$O(n^2)$$ algorithms, it will require $$O(n^2)$$ swaps in the worst-case. It is probably the simplest to understand. At each step, if two adjacent elements of a list is not in order, they will be swapped. Thus, smaller elements will "bubble" to the front, (or bigger elements will be "bubbled" to the back, depending on implementation) and hence the name. This algorithm is almost never recommended, as insertion sort has the same asymptotic complexity, but only require $$O(n)$$ swaps.

Pseudo-code
func bubblesort( var a as array ) for i from 1 to N       for j from 1 to N - 1 if a[j] > a[j+1] swap( a[j], a[j+1] ) end func
 * a is an array.