SortingLab

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!

Game options

Choose game preferences:

Choose game mode:

Choose game difficulty (amount of elements):

Time:

0:60

Lives:

❀️❀️❀️

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Game over!