## DEV Community is a community of 643,323 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Coder Woman

# What is an algorithm? - absolutely the most straightforward definition!

Aga Wozniak
Creative Web Developer with 7+ years experience

In this episode, you will learn what an algorithm is and why it is essential in the programming world.
Let’s get started!

# What is an algorithm at all?

Each computer program consists of instructions on what the computer should do step by step.
You’ve probably prepared a meal with a recipe at any time. Do you want to make spaghetti?
Step 1: fry the onion and meat in a pan.
Step 2: add herbs and tomatoes.
Step 3: cook for 30 minutes.
Step 4: cook the pasta al dente.
Step 5: serve pasta with sauce and grated cheese.
Each step should be performed correctly and with the right ingredients to achieve a specific result – in this case, delicious spaghetti.

Our recipe is just an algorithm – instructions on what steps should be taken to achieve a specific goal.
Just as spaghetti can be prepared in many ways, programming problems can be solved using different algorithms.

Of course, algorithms can be more complex (and most often, they are).
They may, for example, be based on conditions.
Example? Here you go fishing. When we break down this activity into step-by-step instructions, i.e., an algorithm, it looks like this:

Step 1: put the worm on the hook
Step 2: throw the bait into the water
Step 3: observe the float until it is submerged in the water
then we have the condition:
has the float submerged or not?
If not: keep watching.
If yes: get the fish out of the water and repeat steps from step 1.
If you’re done fishing, pack your things and go home.

Remember! Computers are not masters of thinking, so if you forget about the last step, you will be sitting there until the end of the world 😉

# Examples straight from the IT world

If you are using the Google Maps application, you are dealing with AI algorithms. This is called a path-finding algorithm whose task is to find the most optimal route between selected points.

Another example can be the principle of an ATM. You come over, insert the card, and hand over the pin. If it is correct, you are asked for the amount of money to be withdrawn and get the money. If the pin is wrong, then you won’t get your money. All steps in the process of withdrawing cash from an ATM are based on algorithms.

This is how we communicate with the computer. Thanks to algorithms and writing out a sequence of instructions, we solve specific programming problems. We do this before we actually start writing the code. Thanks to this, we can write it more efficiently, because we have clearly written instruction!