

If the first value is greater than the second, their positions are switched.

The bubble sort works by passing sequentially over a list, comparing each value to the one immediately after it. It may be applied to a set of data in order to sort it.įor comparing various sorts, see compare sorts.įor other sorting algorithms, see sorting algorithms, or:Ī bubble sort is generally considered to be the simplest sorting algorithm.Ī bubble sort is also known as a sinking sort.īecause of its simplicity and ease of visualization, it is often taught in introductory computer science courses.īecause of its abysmal O(n 2) performance, it is not used often for large (or even medium-sized) datasets.
