We explore what an algorithm is, how it works and its impact on business decision-making. Find out how algorithms work!
In recent years, algorithms have become a major player in the technological world, first because of the rise of social media and, more recently, with the revolution of generative artificial intelligence and its most known example, Chat GPT.
Although social media and chatbots are their most visible face, the influence of algorithms extends beyond social networks. Understanding what algorithms are and how they work does not only give us a clearer picture of the forces shaping our modern societies, but also of how systems operate in general.
What is an algoritm?
In essence, an algorithm is simply a well-defined process or set of instructions designed to perform a specific task or solve a specific problem. In computing, algorithms are the basis of programs and software, providing a clear and unambiguous sequence of steps that, when followed, lead to the desired result by the machine or software.
Probably the simplest way to explain what an algorithm is is to compare it to a cooking recipe, which, outside the technological realm, is still an algorithm.
Algorithms can be expressed in various forms, such as natural language, pseudocode, flowcharts or directly implemented in programming languages.
The versatility of algorithms is reflected in their wide range of applications, covering a variety of uses. However, there are a number of premises that all algorithms fulfil.
Algoritthms: Key Concepts
- Input: Algorithms usually start from a set of input data to produce a result. However, some algorithms work without input data.
- Output: They generate a result based on the inputs provided.
- Definition: Each step of the algorithm must be precisely and unambiguously defined.
- Finiteness: The algorithm must terminate after a finite number of steps.
- Effectiveness: Each step of the algorithm must be feasible and achievable by basic operations.
How do algorithms work?
As we have already seen, algorithms work by following a set of instructions designed to perform a specific task or solve a problem.
-
Definition of the problem:
- Before designing an algorithm, it is crucial to have a clear understanding of the problem being addressed. Precisely defining the problem helps determine the objectives and requirements that the algorithm must meet.
-
Algorithm design:
- In this stage, the detailed plan for solving the problem is created. This involves identifying the specific steps to be performed, the logic behind each step and how they interact with each other. Different design techniques can be used, such as divide and conquer, greedy algorithms or dynamic programming.
-
Implementation:
- Implementation involves translating the algorithm design into a specific programming language. This step involves writing code that follows the instructions and logic defined during design.
-
Data input:
- Algorithms generally require input data to function. This data can be provided by a user or extracted from some external source. The quality and relevance of the input data can influence the performance of the algorithm.
-
Processing:
- During this phase, the algorithm performs operations and calculations on the input data according to the defined instructions. Each step is executed in sequence, gradually transforming the input data into the desired output
-
Output:
- The result or output of the algorithm is presented to the user or used to perform subsequent actions. It can be a numerical value, a data set, a message, or any other information relevant to solving the problem.
-
Analysis and optimization:
- After implementation, an analysis of the algorithm's performance is performed. Its efficiency in terms of time and space is evaluated, and adjustments can be made to optimise its performance.
-
Iteration (if necessary):
- Depending on the results obtained, it may be necessary to iterate on the previous steps to improve the algorithm. This may involve adjustments to the design, implementation or optimisation.
In most cases, algorithms rely on sets of input data that are processed to generate a specific result. For example, an algorithm may be provided with a set of numbers with the task of sequentially sorting them. In this scenario, the numbers constitute the input, the algorithm represents the sorting process, and the output consists of the same input numbers sorted as directed.
However, not all algorithms require a tangible input. For example, a random number generator has no defined input beyond the user's request to produce a random output.
Algorithms by programming language
Algorithms are written in a variety of programming languages, the best known, C++, Javascript and Python. However, these languages need not be exclusively "computer languages". Returning to the previous example of cooking recipes, non-computer algorithms, such as recipes, can be expressed in a simple language such as English. Although the language used matters depending on the purpose of the algorithm and where it will be applied, in theory, an algorithm can be written in any language. In practice, however, most algorithms are translated into programming languages.
Algorithms: time complexity and space complexity
Time complexity and space complexity are two fundamental aspects in the evaluation and analysis of algorithms. These concepts allow us to understand how an algorithm behaves in terms of execution time and memory usage as the size of the input data increases.
Time Complexity
The time complexity of an algorithm refers to the time it takes to run as a function of the size of the input data. In other words, it analyses how the execution time increases as the data grows. The notation Big O (O) is commonly used to describe time complexity, expressing the worst-case execution of the algorithm.
Understanding time complexity is essential for evaluating the efficiency of an algorithm and making informed decisions about its applicability in different contexts.
Space complexity
The space complexity of an algorithm is related to the amount of memory it uses as a function of the size of the input data. It analyses how the algorithm's memory requirements increase as the input data increases. Like time complexity, spatial complexity is commonly expressed with the notation Big O. It is crucial to consider spatial complexity when designing algorithms, especially in resource-constrained environments.
Taken together, understanding time and space complexity provides a comprehensive view of an algorithm's performance. An efficient algorithm should seek to minimise both execution time and memory usage, ensuring optimal performance in a variety of situations.
The problem with algorithms
Although culture often portrays algorithms as some kind of supernatural power that can do anything, the truth is that algorithms neither have superpowers nor are they capable of solving every problem. Vincent Warmerdam, co-founder of PyData and expert in algorithms and machine learning, addresses this problem in his talk 'The profession of solving (the wrong problem)'. The expert argues that the simple application of algorithms does not guarantee problem solving; in fact, he warns that a well-conceived algorithm can aggravate the situation if used incorrectly. Warmerdam highlights the widespread tendency to trust that algorithms possess the magical ability to solve any problem. In his experience, many of his fellow algorithm experts propose the creation of a "super-algorithm" as an immediate solution to any business challenge presented by a client, without a thorough analysis of the data or assessment of its veracity.
An illustrative example of how blind faith in algorithms can lead to failure is the stock market incident known as the 'Flash Crack' in 2010. In this episode, stock market algorithms caused a sudden market collapse for no apparent reason, followed by an equally inexplicable recovery minutes later. This event perplexed even the algorithm's creators, who were unable to explain its behaviour. This lack of understanding highlighted the limitations of artificial intelligence when it lacks the guidance of natural intelligence, i.e. human intelligence.
Conclusion
In conclusion, algorithms are fundamental tools in the computational field that allow solving problems and performing specific tasks. Their versatility and applicability in various fields make them an essential part of today's technology. However, it is important to bear in mind that algorithms are not a magic solution for all problems and their application requires careful analysis and a deep understanding of the data. Time and space complexity are key aspects to consider when assessing the efficiency of an algorithm.