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.
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.
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:
Algorithm design:
Implementation:
Data input:
Processing:
Output:
Analysis and optimization:
Iteration (if necessary):
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 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.
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.
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.
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.
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.