An algorithm is a sequence of instructions or commands carried out systematically with the objective of solving a problem or performing a task.
The word "algorithm" refers to the Arabic mathematician Al Khowarizmi, who lived in the ninth century, and described rules for mathematical equations.
Algorithms are like a recipe for a cake: a sequence of actions that must be performed until the final goal - the finished cake - is reached.
Algorithms apply from simple everyday tasks to complex computer programs and tools that identify consumer behavior on the Internet.
All computer functions, smartphones and tablets, for example, are the result of algorithms. These machines are capable of performing billions of commands in a few seconds.
Examples of how an algorithm works
Algorithms arise in mathematics to describe the rules for algebraic equations, but they can be applied to any sequence of finite actions that seek to solve a problem.
All the tasks we perform on a daily basis can be transformed into algorithms, just unravel all the necessary actions to reach the determined objective.
If we made an algorithm for preparing coffee, for example, we could have the following steps:
- boil the water;
- put the powder in the filter;
- turn off the water;
- pass the water through the coffee powder.
Algorithms used in computers are more complex and also involve possibilities. Consider the example of a mouse over an internet browser.
The command to close the screen is given by an algorithm that understands that:
- If the mouse clicks on the “x”, the page must be closed;
- If the mouse does not click on the “x”, nothing should be done.
This algorithm can be structured in a flowchart:
Basically, algorithms are composed of input data (input), processing and output data (output). This structure can be easily understood with the example of a calculator:
- Input data: values and operations to be carried out
- Processing: calculations performed by the machine
- Output data: result of the operation
Algorithms are used in computer programming
Algorithm is a very important concept for programming, as all machines and computer programs work from sequences of finite actions that lead to the performance of a task.
The role of the person who makes the programming of computers and software is to think about all the steps of the tasks and describe them in an objective and clear way so that the computer can carry them out.
An example would be a program that shows whether or not a student has passed a particular subject. Considering that the final grade is the average of the two tests taken in the semester, the commands would be:
- Collect the grade in the two tests performed;
- Calculate the arithmetic mean between them;
- If the result is greater than 7, the student passed;
- If the result is less than 7, the student has failed.
However, computers do not understand the language written in this way, so programmers must "translate" these commands into programming languages. Some examples of programming language they are:
- Java
- C language
- C++ language
- C language#
- Python
The operations of an algorithm are performed very quickly by machines. A typical notebook, for example, typically performs more than a billion operations per second.
This speed of operation revolutionized the computational world, as machines can perform calculations in a very short time that humans would take days, months or even years to perform.
Algorithms on the internet
Algorithms are also used on the internet, especially by search engines and social networks.
Use of algorithms in search engines
One of the most remembered examples is the Google search engine algorithm, which performs several operations to organize the way search results appear to the user.
When a user searches Google for a keyword, such as "what is democracy", the order of the result shown depends on several calculations that the algorithm performed to put them in that position.
These calculations are based on several variables, such as the quality and timeliness of the content, the quality of the site the content is on, and how long people tend to stay on that page.
Google's algorithm is quite complex and is updated from time to time in order to provide a better experience and present the best results for users.
Use of algorithms in social networks
Social networks are also programmed with complex algorithms. You feeds Facebook, Instagram and Twitter, for example, show posts and advertisements according to user behavior.
This means that not all posts from your friends will appear in yours. feed. The algorithms of these social networks select the ones that make the most sense according to your preference.
Facebook's algorithm, called the EdgeRank, for example, selects the most relevant content for you according to several factors, such as:
- Publications and pages you like;
- People you interact with;
- Pages where you leave comments;
- Your shares.
Spotify is another example of an app and social network that uses algorithms to provide users with a more personalized experience. Every week the app offers a playlist called “Discoveries of the Week”.
That playlist contains 30 songs that have never been played by the user in the app, but that are similar to other songs he usually listens to.
The objective is to present to the user the songs and bands that he doesn't know yet, but that are probably compatible with his musical taste.
See also the meaning of software and hardware.