Solving a problem in a set order
Algorithm isn't a hard word. It's "a set order for solving a problem." Like cooking noodles, or finding a route. Once the order is set, anyone gets the same answer.
The order for making a sandwich
Say you're making a sandwich.
Take out the bread,
spread the jam,
cover it with bread.
Walk through this set order
one step at a time,
and the sandwich is done.
This is an algorithm.
A set order, one step at a time. (Take bread โ spread jam โ cover โ cut โ done)
The "algorithm" that sounded hard
is really just this.
"What to do first,
and what to do next"
an order, set in advance.
A recipe, an assembly guide,
they're all algorithms too.
Socks first, or shoes first?
The order isn't there for nothing.
Put on socks, then shoes,
and it works fine.
But put shoes on first,
then try the socks?
It won't work.
If the order is wrong,
the result is wrong.
Try changing the order. (Right order โ works ยท reversed order โ doesn't)
So in an algorithm
the order really matters.
What you do first
can make it work
or not work.
It's not just knowing the steps,
but knowing the right order.
Same order, same result
Here's the power of a set order.
If I follow that order,
and a friend follows that order,
we both get the same answer.
It doesn't sway with mood or luck.
As long as the order is the same,
the result is the same.
Follow the same order, both get the same answer. (Me โ 7 ยท friend โ 7)
Why is that good?
Because you can trust it.
"Follow this order
and you'll surely get this answer."
So if you write this order
for a computer too,
it'll always do the same thing.
Finding the bigger of two numbers
Let's follow one truly small algorithm.
Finding the bigger of two numbers.
"Compare the two,
pick the bigger one."
That order is all it takes.
Put in the input, out comes the answer.
Input โ order โ answer. (Number A 7 ยท number B 4 โ compare โ answer 7)
Seems like nothing, right?
But small orders like this,
gathered and gathered,
do amazing things.
Lining up thousands,
finding just what you want.
All the power of a "set order."
To make a computer do it
A computer can't
figure things out "on its own."
What to do, in what order,
we have to write it down.
That order is exactly an algorithm.
Write it well,
and a computer does it fast and exactly.
Once you know order, now. (Algorithm = an order for solving โ sorting ยท searching ยท beyond)
From now on, whatever algorithm you see,
don't be scared.
However complex it looks,
inside it's the same.
"What to do first,
and what to do next"
just an order, set in advance.