Algorithm

Table of contents

Summarise with:

The algorithm is one of the most basic concepts that needs to be understood in order to enter the world of programming and develop a programmer's mindset.. 

You may have heard about the algorithms in some conversations about technology or that you remember it from high school mathematics classes. It is very common to talk about the algorithms social networking sites like Tiktok or Instagram, which decide which posts to show you at any given time.

What exactly is an algorithm in computer science?

In a nutshell, an algorithm is nothing more than a series of steps that follow a certain order. and specific actions aimed at solving a problem or task.

Although Algorithms apply only to mathematics, logic and programming, they can also be extrapolated to our daily lives. 

After all, complex tasks such as preparing a plate of spaghetti, putting on a washing machine or cleaning a room also require following instructions that are made up of different steps. While they may vary from person to person, the skeleton remains very similar.

And the fact is that the algorithms are just that: a set of instructions that, if completed, allow us to make decisions to carry out a particular task.

Steps of an algorithm

Broadly speaking, a algorithm programming is governed by the following three steps:

  • Input: The algorithm receives pre-existing information that it needs to operate.
  • Processing: The system analyses the input and checks that it is correct. It then executes a series of commands to produce the desired result.
  • Output: The algorithm provides a solution to the requested task and terminates.

This output or result that the algorithm gives us can be correct or incorrect. And how does a programmer know that an algorithm is correct? By introducing various inputs and comparing its output with a confirmed solution that has been arrived at manually.

However, it is often impossible to test the correctness of an algorithm based on manual mathematical operations because of the complexity and time involved. This is why we can often say that an algorithm is correct when the input is correct.

Remember that an algorithm always executes the same commands systematically, and will only vary according to the information we provide it with.

Example of an algorithm

To help you understand how an algorithm works, we illustrate it with a simple example based on the preparation of a tea.

  • Step 1: Gather the necessary ingredients: Water, tea bag and sugar (optional).
  • Step 2: Boil the water in a kettle.
  • Step 3: Place the tea bag in a cup.
  • Step 4: Pour the hot water into the cup.
  • Step 5: Let the tea steep for a few minutes to infuse.
  • Step 6: Remove the tea bag from the cup.

At this point we must ask ourselves: do we want to add sugar to the tea, saccharin or nothing at all?

  • Step 7 - A (sugar): Add sugar according to personal taste.
  • Step 7 - B (saccharin): Add saccharin according to personal taste.
  • Step 8: Stir the tea to mix in the sugar (if added).
  • Step 9: Ready! Now you can enjoy a hot cup of tea.
     

Let's consider the input as the first step, as we gather the necessary elements to prepare the tea and introduce them into the process from the very beginning.

The rest of the steps that we execute little by little to elaborate the tea would represent the whole process that an algorithm goes through to show the desired result.

By pouring the tea to drink, we would be getting an output and a subsequent termination of the algorithm.

Share in:

Related articles

VoIP

VoIP, an acronym for «Voice over Internet Protocol», is a technology that allows the transmission of voice calls over the internet instead of using traditional telephone networks. VoIP converts

DLP

DLP, or data loss prevention, is a cybersecurity strategy and set of technologies designed to protect sensitive and confidential information against unauthorised leaks. Its main objective is to prevent the leakage of critical data, such as financial, proprietary, and other sensitive information.

IT auditor: what does he do and what is his salary?

IT has become one of the pillars of many companies, as it allows them to manage all their processes and tasks more efficiently. For this reason, the figure of the IT auditor was born, who is in charge of compiling all the information

Challenges and best practices for protecting data privacy in the digital age

Nuestros datos personales ya no solo están almacenados en herméticos registros físicos de la Administración Pública, sino que nosotros mismos hemos plagado Internet de información personal, expuesta o no al mundo. La gestión responsable de la información personal también forma parte de las políticas

Scroll to Top