Algorithm
Bubble Sort
Bubble Sort is one of the simplest sorting algorithms that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The algorithm gets its name because smaller elements "bubble" to the top of the list with each iteration. While conceptually simple, Bubble Sort is primarily used for educational purposes due to its inefficiency with large datasets. Its average and worst-case time complexity is O(n²), making it impractical for real-world applications with significant data. However, it has the advantage of being able to detect if the list is already sorted (best-case O(n) with optimization) and requires minimal extra memory space.
Visualization
Press Play or step forward to watch the algorithm run.