Explainer: What is an algorithm?

Computers and others use these step-by-step rules to answer questions and process data

a blue glowing flowchart illustration

A step-by-step collection of rules for carrying out some calculation or conducting some process, as mapped in this flow chart, is known as an algorithm. Computers perform everything they do by following the directions provided by mathematical algorithms.

Olena_T/E+/Getty Images

An algorithm is a precise step-by-step series of rules that leads to a product or to the solution to a problem. One good example is a recipe.

When bakers follow a recipe to make a cake, they end up with cake. If you follow that recipe precisely, time after time your cake will taste the same. But deviate from that recipe, even a little, and what emerges from the oven may disappoint your taste buds.

Some steps in an algorithm depend on what happened or was learned in earlier steps. Consider the cake example. Dry ingredients and wet ingredients might need to be combined in separate bowls before they can be mixed together. Similarly, some cookie batters must be chilled before they can be rolled out and cut into shapes. And some recipes call for the oven to be set to one temperature for the first few minutes of baking, and then changed for the rest of the cooking or baking time.

We even use algorithms to make choices throughout the week.

Let’s say you have an afternoon with nothing planned — no family activities, no chores. To settle on what to do, you will likely think through a series of smaller questions (or steps). For instance: Do you want to spend time alone or with a friend? Do you want to stay inside or go out? Do you prefer to play a game or watch a movie?

At each step you will consider one or more things. Some of your choices will depend on data you gathered from other sources, such as the weather forecast. Perhaps you realize that (1) your best friend is available, (2) the weather is warm and sunny, and (3) you’d love to play basketball. Then you might decide to go to a nearby park so the two of you can shoot hoops. At each step, you made a small choice that got you closer to your ultimate decision. (You can create a flowchart that lets you map the steps to a decision.)

Computers use algorithms, too. These are the sets of instructions a computer program must follow in order. Instead of a step in a cake recipe (such as mix flour with baking powder), the computer’s steps are equations or rules.

Awash in algorithms

Algorithms are everywhere in computers. The most well-known example might be a search engine, such as Google. To find the closest veterinarian that treats snakes or the fastest route to school, you might type the relevant question into Google and then review its list of possible solutions.

Mathematicians and computer scientists designed the algorithms that Google uses. They realized that searching the whole internet for the words in every question would take too long. One shortcut: Count the links between webpages, then give extra credit to pages with lots of links to and from other pages. Pages with more links to and from other pages will rank higher in the list of possible solutions that emerge from the search request.

Many computer algorithms seek new data as they work through a solution to some problem. A map app on a smartphone, for example, contains algorithms designed to find the fastest route or perhaps the shortest one. Some algorithms will connect to other databases to identify new construction zones (to avoid) or even recent accidents (which can tie up traffic). The app also may help drivers follow a chosen route.

Algorithms can become complex as they gather lots of data from different sources to reach one or more solutions. The steps in most algorithms must follow a set order. Those steps are called dependencies.

One example is an if/then statement. You acted like a computer algorithm when you decided how to spend your afternoon. One step was to consider the weather. IF the weather is sunny and warm, THEN you (might) choose to go outside.

Algorithms sometimes also glean data on how people have used their computers. They may track what stories or websites people have read. Those data are used to offer these people new stories. This can be helpful if they want to see more stuff from the same source or about the same topic. Such algorithms can be harmful, however, if they prevent or in some way discourage people from seeing new or different types of information.

We use computer algorithms for so many things. New or improved ones emerge every day. For instance, specialized ones help explain how diseases spread. Some help predict the weather. Others choose investments in the stock market.

The future will include algorithms that teach computers how to better understand more complex data. This is the beginning of what people call machine learning: computers teaching computers.

Another area being developed is a faster way to sort through images. There are apps that pull up possible plant names based on a photograph. Such tech currently works better on plants than it does on people. Apps that are designed to recognize faces may be fooled by haircuts, glasses, facial hair or bruises, for instance. These algorithms are still not as accurate as people tend to be. The trade-off: They’re much faster.

This video explains the history behind the term algorithm and who it’s named after.

But why are they called algorithms?

Back in the 9th century, a famous mathematician and astronomer made a lot of discoveries in science, math and the number system that we now use. His name was Muhammad ibn Mūsa al-Khwarizmī. His last name is Persian for the area of his birth: Khwãrezm. Over the centuries, as his fame grew, people outside the Middle East altered his name to Algoritmi. This version of his name would later be adapted as the English term that describes the step-by-step recipes we now known as algorithms.

More Stories from Science News Explores on Computing