Sorting, Explained Like You're Five: Bubble Sort
Imagine a row of kids lined up for a photo, all different heights, all jumbled up. The photographer wants them shortest to tallest. How do you fix the line without a single tape measure?
You use the same trick a computer uses. It's called bubble sort, and it's one of the first things people learn when they study how computers put things in order.
The whole idea in one sentence
Walk down the line two kids at a time. If the one on the left is taller than the one on the right, have them swap spots. Keep walking. That's it.
Do that over and over, and the tallest kid always drifts to the end — like a bubble floating up to the top of a glass. That's where the name comes from.
Watch it happen
Here's a row of numbers instead of kids. Hit Play and watch them compare and swap, step by step, until they're shortest to tallest. You can pause, step forward one move at a time, or slow it down.
See how the orange bars are the two being compared right now? When the left one is bigger, they trade places. And once a number reaches its final home at the end, it locks in and stops moving.
Why anyone cares (especially in interviews)
Bubble sort is rarely the fastest way to sort things — but that's exactly why interviewers love it. It's simple enough to explain out loud, so it's a perfect way to show you understand how an algorithm actually thinks: compare, swap, repeat, and know when you're done.
Master this one and you've got the mental model for every sorting algorithm that comes after it. They're all just smarter versions of "compare two things and put them in the right order."
The goal isn't to memorize the steps. It's to be able to explain it to a five-year-old. If you can do that, you actually understand it.