Putting the jumbled in line
Ever lined up by height? Sorting is putting jumbled things into order, in a line. The trick is simple. Compare height with your neighbor, bigger one back. Repeat it, and the line falls into order.
What is sorting?
Told to line up by height,
at first everyone's jumbled.
Sorting is putting this
from smallest to biggest,
into a line in order.
Below, compare "jumbled"
and "lined up"
side by side.
Jumbled vs lined up. (Jumbled → from smallest to biggest)
A lined-up row looks nice,
but what matters more,
with order in place,
it's easy to find things later.
A dictionary is like that.
In alphabetical order,
you find a word in no time.
Measuring against your neighbor
How do we make the line?
The trick is very simple.
Look at two standing side by side.
If the left is bigger,
swap their places.
Small one to the front,
big one to the back.
That one move is all of it.
If the left is bigger, swap. (Compare the two → bigger one goes back)
Just two compared.
Two at a time,
swap if bigger,
leave it if smaller.
No complicated thinking.
This simple move,
repeated again and again.
The big one moves back
Now let's really sort.
From the left, comparing neighbors,
push the bigger one back.
Go around once,
and the biggest settles at the very end.
Repeat it,
and the line falls into order step by step.
Press the button and watch.
Repeat comparing and swapping. (Yellow = comparing · red = swapping · green = settled)
Watch the big bar
float to the back like a bubble.
Once each round,
it finds its place.
Simple compares and swaps,
gathered and gathered,
make a whole ordered line.
Why does it end up right?
Each time you go around,
the biggest settles at the back.
Two rounds, the second biggest,
three rounds, the third.
Filling one at a time
from the back like this,
repeat the rounds
and eventually it's all in order.
One settles each round. (Repeat the rounds and the line completes)
So sorting is reliable.
However jumbled it is,
repeat the rounds
and the line surely falls into order.
Slow or fast,
keep the steps,
and the end is certain.
The good of a sorted line
Sorting is truly everywhere.
Ranking by score,
listing names alphabetically,
showing goods by price.
Above all,
with the line in order,
it's far easier to find things.
That's the next story.
Once it's lined up, now. (Sorting = ordering in a line → searching · ranking · beyond)
Putting things in line
is useful on its own,
but it's also prep for "what's next."
Tidy it up
and finding, choosing, gets easier.
The power of order
is bigger than you'd think.