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

DLL

What is a Dynamic Link Library (DLL)? A Dynamic Link Library, known as a DLL, is a type of file used in Windows operating systems to share code, data and resources between various applications. Unlike

Target blank

The attribute target=»_blank» is a property of the HTML (HyperText Markup Language) language, used within the link tags (<a>), which tells the browser that the link destination should be opened in a new tab or window. This functionality is particularly useful when

Mixed reality

Mixed reality (MR) is an emerging technology that combines elements of virtual reality (VR) and augmented reality (AR), creating an environment where the physical and digital worlds coexist and interact in real time. This fusion allows users to see

Generative AI

Generative Artificial Intelligence (Generative AI) is an exciting branch of artificial intelligence that focuses on creating new and original content. Unlike traditional AI applications, which generally analyse and process data, Generative AI has

Scroll to Top