Back

This article needs additional citations for verification. (November 2016) (Learn how and when to remove this template message) |

Static visualization of bubble sort ^{[1]} | |

Class | Sorting algorithm |
---|---|

Data structure | Array |

Worst-case performance | comparisons, swaps |

Best-case performance | comparisons, swaps |

Average performance | comparisons, swaps |

Worst-case space complexity | total, auxiliary |

**Bubble sort**, sometimes referred to as **sinking sort**, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.

This simple algorithm performs poorly in real world use and is used primarily as an educational tool. More efficient algorithms such as quicksort, timsort, or merge sort are used by the sorting libraries built into popular programming languages such as Python and Java.^{[2]}^{[3]}

**^**Cortesi, Aldo (27 April 2007). "Visualising Sorting Algorithms". Retrieved 16 March 2017.**^**"[JDK-6804124] (coll) Replace "modified mergesort" in java.util.Arrays.sort with timsort - Java Bug System".*bugs.openjdk.java.net*. Retrieved 2020-01-11.**^**Peters, Tim (2002-07-20). "[Python-Dev] Sorting". Retrieved 2020-01-11.