Bubble sort: where the slowest of the slow get to go first.
Bubble sort is a sorting algorithm that works by repeatedly iterating through a list of items and swapping adjacent elements if they're in the wrong order. It's like trying to get your aunt's hair to match the colors of the rainbow, but instead of hair dye, you're using algorithms.
Here's a step-by-step guide:
Example: 5, 1, 4, 2, 3
1. Compare 5 and 1: swap.
1. 1, 5, 4, 2, 3
2. Compare 5 and 1: no swap.
2. Compare 5 and 4: swap.
3. Compare 5 and 2: swap.
4. Compare 5 and 3: no swap.
And so on...
Want to see the algorithm in action? View the animation