

Step-by-step visualisation of the bubblesort sorting algorithm, generated with software from here, cropped using GIMP Tags: Bubble Sort View |
Tags: Bubble Sort View |
Tags: Bubble Sort View |
|||||||||
Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swap (Swap (computer science))ping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort.
Class: Sorting algorithm
Data: Array (Array data structure)
Best-time: O(n)
Average-time: O(n^2)
Time: O(n^2)
Space: O(1) auxiliary
Optimal: No