seegongsik
Algorithms

What is an algorithm

"Algorithm" isn't a hard word. It means "a set order of steps for solving a problem." Like cooking noodles or finding your way, once the order is set, anyone who follows it gets the same answer.

01

The steps for making a sandwich

Say you're making a sandwich.
Take out the bread, spread the jam, put the other slice on top.
Follow these set steps one by one and the sandwich is done.
That's an algorithm.

1Take out two slices of bread
2Spread jam on one
3Cover with the other slice
4Cut it in half
Done! The sandwich is ready
Press one step at a time. Walk the order and the problem gets solved.

Each press of "next step" moves the order forward one step. Take out bread → spread jam → cover → cut → done.

That word "algorithm" that sounded so hard is really just this.
Deciding what to do first and what to do next: setting the order.
Recipes and assembly instructions are all algorithms, in a way.

02

Socks first, or shoes first?

Order isn't arbitrary.
Put on your socks and then your shoes, and it works.
But try putting on your shoes first and then your socks, and it doesn't.
Wrong order, wrong result.

1Put on socks
2Put on shoes
Dressed just right
Even the same two steps: change the order and the result changes.

Change the order and the result changes. Right order → it works · reversed order → it doesn't.

That's why order matters so much in algorithms.
What you do first decides whether it works or not.
It's not just knowing the steps; it's knowing the right order.

03

Same order, same result

Here's the power of a set order.
If I follow it and my friend follows it too, we both get the same answer.
It doesn't depend on mood or luck: same order, same result.

Me
3 plus 4
= adding in order
?
Friend
3 plus 4
= adding in order
?
Follow the same order and anyone gets the same answer. That is the power of an algorithm.

Follow the same order and both get the same answer. Me → 7 · friend → 7.

This is good because you can rely on it.
"Do it in this order, and you'll always get this answer."
So if you write this order down for a computer, it does the same thing every time.

04

Finding the bigger of two numbers

Let's follow one really small algorithm together.
It finds the bigger of two numbers.
"Compare the two, pick the bigger one." That order is all it takes.
Put in the input and out comes the answer.

Number A
7
Number B
4
1. Look at the two numbers A and B (7, 4)
2. Compare whether A is bigger than B (7 > 4?)
3. Pick the bigger side
Press the button to solve in order
Walk the set order, and from the input (7, 4) comes the answer (7).

Input → steps → answer. Number A 7 · number B 4 → compare → answer 7.

It may not look like much, but small orders like this, piled up, do amazing things.
They line up thousands of items and find what you're looking for.
It's all the power of a set order.

05

To have a computer do it

A computer can't figure things out on its own.
We have to write down what to do and in what order.
That order is the algorithm, and if we write it well, the computer does the job quickly and accurately.

Algorithm = an order for solving problems
Set steps · the right order · the same answer for anyone. You have the basics.
Sorting
Lining up what is jumbled
Searching
Finding what you want
Beyond
Smarter orders
Next we'll look at breaking a problem into small steps, and after that at "sorting," putting jumbled things in order.

Now that you know the idea of order, what's next. Algorithm = steps for solving a problem → sorting · searching · beyond.

Whatever algorithm you meet from now on, there's no need to be intimidated.
However complicated it looks, inside it's the same.
It's just an order that says what to do first and what to do next.

In one lineAn algorithm is "a set order of steps for solving a problem." Follow the steps and you get the answer; get the order wrong and the result is wrong. The same order gives anyone the same answer, so if you write the order down for a computer, it does the same thing every time.
← Algorithms
Was this helpful? Support seegongsik