Bubble sort
How it works
Bubble Sort works by repeatedly comparing and swapping adjacent elements if they are in the wrong order. The largest elements "bubble up" to the end, just like bubbles rising in water!
-
πΉ Compare two elements β Swap if needed β Repeat until sorted.
-
πΉ Best case: Already sorted? β Only takes O(n) time!
-
πΉ Worst case: Lots of swaps, runs in O(nΒ²).
-
πΉ Why learn it? It's simple and helps you understand swapping logic.
π Think of it as: Sorting a deck of cards by repeatedly checking neighbors.
How it works in code
How to play
Goal: Swap adjacent elements until the list is sorted.
Buttons:
-
Skip βοΈ β Moves to the next pair without swapping.
-
Swap π β Swaps the current two elements.
-
Submit β β Checks if the list is fully sorted.
π Tip: Keep swapping until the largest elements "bubble up" to the end!
Time:
0:60
Lives:
β€οΈβ€οΈβ€οΈ