Bubble Sort
A simple sorting algorithm that repeatedly swaps adjacent elements.
Time Complexity
O(n^2)
SlowSpace Complexity
O(1)
ImmediateIn-Place
Yes
YesStability
Yes
YesDifficulty
Easy
★★☆☆☆Description
Bubble Sort is a straightforward sorting algorithm 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 pass.
Steps:
- Compare adjacent elements
- Swap if needed
- Repeat until the list is sorted
While it is easy to understand and implement, Bubble Sort is inefficient on large datasets. However, it can be optimized to detect if the array is already sorted.