Bubble Sort
Bubble Sort is a simple comparison-based 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.
Steps:
- Compare adjacent elements and swap if they are in the wrong order
- After each iteration, the largest element bubbles up to the end
- Repeat for all elements until no swaps are needed
Time Complexity
Best: O(n)
Average: O(n²)
Worst: O(n²)
Space Complexity
O(1)
Array length:
7
Speed: