Skip to main content
28 March 2022
Follow Us

Do we know really what an algorithm is?

These  terms are becoming increasingly popular in everyone's daily life, but do you really know what an algorithm is and what it needs to be processed?

I'll start this article with the following statement:

All (yes, really all 🤯) problems can be solved in a simple manner: with modeled algorithms and logic.

First, I will introduce a pillar from a type of reasoning that has enabled all the technological advances that we currently have: Computational Thinking:    

  •  Deconstruction  

Picture20.png

It consists of dividing complex problems into smaller parts and easier to solve.

For example, if you try to build a 20-story building at once, it might seem impossible, right?

However, if brick-by-brick you build the first floor, and after several small steps evolve to the second floor, until you reach the twentieth floor, it would be a problem with a more visible solution (exactly as it happens in practice 😲).

This is exactly how it occurs with major computational problems and complex algorithms, like the cases of Google and Facebook, which have "endless" lines of code but have been built step-by-step.

What is an Algorithm?

In the study of logic, there is a rule for testing theorems called Universal Generalization in which we deduce something and then create a rule.

We could spend days discussing this topic, but I will try to apply it in this article in a simple way. Let's look at the following algorithm:

Preparation of cod with cream.

Ingredients

Preparation

Potatoes 500g

1-Pre-cook the Cod at 200 degrees

Cod 400g

2-Cut the Potatoes

Olive Oil 100ml

3-Cook the cod in a pan

Cooking Cream 250ml

4- Add the potatoes and the cooking cream

And we will have as a result a tasty meal 😋 and perhaps a greater weight on the scale)...

Generalizing the preparation of cod with cream, we can infer that an Algorithm is a sequence of well-defined instructions used to solve problems. Briefly: you will receive something, then modify or perform a job with what you received, and finally return an output.

Some important analogies:

1  . Receival of one or more inputs, in our language 😯

These entries are no more than the data that our algorithm will receive from the outside world. In our example, the ingredients (potatoes, cod, olive oil and cream).

Picture18.png

2. A sequence of steps will be performed: you can change the inputs, modify them, group or separate them depending on the context. That means, following a well-defined sequence of actions. In our example, the preparation (1-Pre-cook the cod, 2-Cut the potatoes, 3-Cook the cod in a pan and 4-Add the potatoes and add the cooking cream).

 

Picture16.png

 

3 . Finally, our algorithm will produce an output. This is what we ultimately wanted to do, that is, our final result. In our example: the cod with cream ready to be savored 😋

 

Picture17.png

What are logical tests?

In the real world, we use logical tests intermittently, but most often unconsciously. Using our cod with cream preparation again, I ask you the following questions:

  • What if we did not have an oven to preheat the cod,  as required by step 1?
  • And if the potatoes were already cut, would it be necessary to cut them again as suggested in step 2?

In general, logical tests are one (or more) question(s) that we ask and expect as a result only two specific values: True or False. After these results, we usually make a specific decision or take an alternative path.

Picture19.png

When we ask the question "Do we have an oven to pre-cook the cod?", we will have two possible results, true or false. Now, it is important to note that depending on our outcome, we would make a different decision for the continuation of our algorithm.

Let us assume that if our answer was true (we have the oven), then our next step would obviously be to start pre-cooking. If the answer was false (meaning that  we do not have a oven), our path would be branched to the purchase of one, since under no circumstances could we go without eating our dear cod with cream 😊.

That being said, logical tests are vital to overcome our obstacles. Since in the real world we have several variables that will determine which path we should take to get the expected result.

Finally, I will revisit the statement we made when we started the article: By dividing our problem (however complex it may be) into a simpler sequence of instructions (Algorithm), and if we combine it with well-structured Logical Tests, the solution can be delivered to our hands. 

Thank you for your attention, and until the next article.

Tiago.

Ficheiros em anexo

Tiago Figueredo

Assine a nossa newsletter e receba o nosso conteúdo diretamente no seu email