Bubble sort compares adjacent elements and swaps them if they are in the wrong order. O(n 2) average and worst. The algorithm is named for the way smaller or larger elements “bubble” to the top of the list. The bubble sort is slow. It is only for beginners to explore the sorting techniques.


Source code

Java

Javascript

Python

Doodle

bubble sort doodle

Download Java, JavaScript and Python code
Bubble sort animated