How to Build a Simple Algorithm Before Putting It Into Code
If you have read our previous article, “Before Code: Learn to Think Like a Programmer”, you already know the first important rule of programming:
Programming does not begin with code. It begins with a problem.
Before opening Python, JavaScript, C, or any other programming language, we should first understand what we are trying to solve.
And once we understand the problem, we need to describe the solution in a clear and logical way.
That solution is called an algorithm.
So, what is an algorithm?
An algorithm is simply a sequence of steps that leads from a problem to a result.
You don't need to be a programmer to use algorithms.
Every day, we follow them without even realizing it.
Imagine that you want to make a cup of coffee.
You could describe the process like this:
-
Get a cup.
-
Put coffee in the cup.
-
Heat some water.
-
Pour the water into the cup.
-
Add sugar if you want it.
-
Stir.
-
Drink the coffee.
Congratulations.
You have just written an algorithm.
There is no Python here.
There is no computer.
There isn't even anything particularly complicated.
But there is something very important:
a clear sequence of actions that produces a result.
The computer needs more precision than we do
Humans are very good at filling in missing information.
If someone tells you:
"Make me a coffee."
you already know what they mean.
A computer doesn't.
You have to tell it what "coffee" means, what ingredients are needed, what order things happen in, and what to do when there are different possibilities.
This is why we need algorithms.
An algorithm takes an idea that is understandable to a human and turns it into a precise sequence of steps.
Let's solve a simple problem
Let's use something a little closer to programming.
Imagine that we want to know whether a car has enough fuel to reach its destination.
We know three things:
-
how much fuel is currently in the tank;
-
how far we need to travel;
-
how much fuel the car uses.
A human can solve this problem quite easily.
But let's slow down and think like a programmer.
First, we need to know what information we have.
Input
We have:
Then we need to calculate something.
Processing
We calculate how much fuel the trip will require.
Then we need to make a decision.
Decision
Is the available fuel greater than or equal to the required fuel?
If yes:
We can leave.
If no:
We need to refuel.
And now we have a complete algorithm.
Notice something important.
We have solved the problem without writing any code.
An algorithm has a structure
Most algorithms can be understood through a few basic ideas.
1. Input
What information do we start with?
For our car:
2. Processing
What do we do with that information?
3. Decisions
Do we need to choose between different possibilities?
4. Repetition
Sometimes we need to do something more than once.
For example:
Or:
This is where programming languages give us mechanisms such as for and while.
5. Output
What is the result?
In our example:
or:
6. A stopping point
An algorithm must also know when it is finished.
If we tell a computer:
"Keep looking for the answer."
we also need to tell it what counts as finding the answer.
Otherwise, the process may continue forever.
The famous programming words are just ways of expressing these ideas
When you start learning programming, you will quickly encounter things such as:
These may look like programming itself.
They aren't.
They are simply tools used by programming languages to express ideas that already exist in the algorithm.
For example:
Python can express that using if and else.
Another language may use a different syntax.
The idea remains the same.
The same applies to repetition.
The algorithm may say:
One language may use for.
Another language may express the same idea differently.
The language changes. The logic doesn't.
The computer doesn't understand "maybe"
There is another important difference between human thinking and algorithmic thinking.
People can say:
"Maybe I'll leave tomorrow."
That's perfectly normal.
A computer needs something more precise.
Maybe under what conditions?
Perhaps:
-
if the car is ready;
-
if there is enough fuel;
-
if the weather is good;
-
if we have enough time.
Now the "maybe" can be transformed into actual decisions.
This is an important part of algorithmic thinking.
We don't simply tell the computer what might happen.
We describe the conditions that determine what should happen.
Don't start with the programming language
This is probably the most important lesson in this article.
A beginner often starts with a programming language and asks:
"What command do I need?"
A programmer should first ask:
"What exactly am I trying to solve?"
Then:
"How would I solve it myself?"
Then:
"Can I describe the solution as a sequence of logical steps?"
Only after that should we ask:
"How do I express those steps in Python?"
This order is extremely important.
The code is almost the last step, not the first.
An algorithm can be written in plain language
You don't need special software to create an algorithm.
You can write it on paper.
You can write it in a text file.
You can draw it as a diagram.
You can use pseudocode.
For example:
This already looks very similar to a program.
But it is still an algorithm.
We haven't decided which programming language will be used.
And that's exactly the point.
The algorithm comes first
Once you have a clear algorithm, translating it into a programming language becomes much easier.
You already know:
-
what information you need;
-
what calculations must be performed;
-
what decisions must be made;
-
what needs to be repeated;
-
what the final result should be;
-
and when the process should stop.
The programming language simply gives you the vocabulary and syntax needed to express those ideas to the computer.
That's why learning programming is not just about memorizing commands.
It's about learning how to think clearly enough to describe a solution.
From problem to program
We can now summarize everything in one simple chain:
Problem → Analysis → Algorithm → Code → Result
And notice where the programming language appears:
after the algorithm.
That's intentional.
Because we don't want to teach you how to write code before you know what the code is supposed to do.
In the next article, we will finally open Python.
But we will skip the traditional:
print("Hello World")
Not because print() is useless, but because printing something on the screen is not the interesting part of programming.
Instead, we'll take an algorithm we already understand and turn it into a real Python program.
Because the goal is not to teach the computer to say:
Hello World.
The goal is to teach you how to tell the computer how to solve a problem.

💬 Comments (0)
💬 Join the conversation
Sign in quickly with your Telegram account to leave a comment.