What Is an Algorithm?
An algorithm is a set of step-by-step instructions for solving a problem or completing a task. It takes some starting information, follows clearly defined steps and produces a result. A precise recipe, step-by-step driving directions and the method you learned for long division are all algorithms. Computers run algorithms constantly, from sorting search results to deciding which posts appear in your feed.
What the word "algorithm" means
Encyclopaedia Britannica describes an algorithm as a systematic procedure that produces the answer to a question or the solution to a problem in a finite number of steps. Merriam-Webster calls it "a specific step-by-step procedure for solving a problem or accomplishing some end."
The key ideas are precision and completion. Each step must be clear enough that it can be followed the same way every time, and the process must eventually finish.
Most algorithms can be described in three parts:
- Input: the information it starts with, such as ingredients, an address or a list of numbers.
- Steps: the instructions that transform the input.
- Output: the result, such as a meal, a route or a sorted list.
Algorithms are not limited to computers. People wrote and followed them for thousands of years before computers existed. Computers simply made it possible to run very long and complex algorithms at enormous speed.
An everyday example of an algorithm
Here is an algorithm for making a cup of tea:
- Check the kettle. If it is empty, fill it.
- Turn the kettle on.
- While the water is heating, put a tea bag in a mug.
- Keep checking the kettle until the water boils, then pour the water into the mug.
- Wait three minutes.
- Remove the tea bag.
- If you take milk, add it.
- Serve.
Simple as it is, this contains the three building blocks found in almost every computer algorithm:
- Sequence: steps happen in a set order. You pour the water before removing the tea bag.
- Decisions: the next step depends on a condition. "If it is empty, fill it."
- Repetition: a step continues until something is true. "Keep checking the kettle until the water boils."
A navigation app works the same way at a larger scale. The input is your starting point and destination. The steps compare possible roads, travel times and traffic. The output is a suggested route.
What makes something an algorithm
Computer scientist Donald Knuth, in his classic book The Art of Computer Programming, describes five important features of an algorithm:
- Finiteness. It must always finish after a limited number of steps.
- Definiteness. Each step must be precisely defined, with no room for guessing.
- Input. It has zero or more inputs given to it at the start.
- Output. It produces one or more outputs related to the inputs.
- Effectiveness. Each step must be basic enough that it could, in principle, be carried out exactly, even by a person with pencil and paper.
This is why "make something nice for dinner" is not an algorithm, but a recipe with measured ingredients and timed steps is.
How computers use algorithms
Nearly everything a computer does involves algorithms. Some common examples:
- Search: finding the pages most relevant to what you typed.
- Sorting: arranging emails by date or products by price.
- Navigation: calculating the fastest route between two places.
- Compression: shrinking photos and videos so they send faster.
- Security: scrambling data so only the intended recipient can read it.
- Recommendations: suggesting what to watch, read or buy next.
Some algorithms are very old. Euclid's algorithm, a method for finding the greatest common divisor of two numbers, was described in Euclid's Elements around 300 BCE. Britannica notes that, with minor modifications, computers still use it.
The word itself is old too. "Algorithm" comes from the name of the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi, through the Latin title of a translation of his work on numbers.
What are algorithms on social media?
When people talk about "the algorithm" on social media, they mean the systems a platform uses to decide which posts, videos and ads to show each person, and in what order. There is rarely a single algorithm. Meta said in 2023 that it had published 22 "system cards" describing different AI systems that rank content across Facebook and Instagram.
These systems predict what you are most likely to engage with, based on signals the platforms describe publicly:
- Instagram said in 2023 that its Feed ranking considers your activity (posts you have liked, shared, saved or commented on), information about the post (such as how quickly people are engaging with it), information about the person who posted, and your history of interacting with that person.
- TikTok said in 2020 that its For You recommendations draw on your interactions (videos you like or share, accounts you follow, comments), video information (captions, sounds and hashtags) and device and account settings. It said a strong signal, like watching a longer video to the end, carries more weight than a weak one.
- YouTube says it uses viewing behavior, likes, dislikes, subscriptions and feedback, including satisfaction surveys.
Platforms change these systems often, so their public explanations are snapshots in time. Most offer some controls, such as hiding content, marking "not interested" or switching to a chronological feed. In the European Union, the Digital Services Act requires the largest platforms to offer users a feed option that is not personalized based on profiling.
What is an AI algorithm?
An AI algorithm is an algorithm used to build or run an artificial intelligence system. The most important type today is a machine learning algorithm: a procedure that lets a computer learn patterns from examples instead of following rules a person wrote for every situation.
This is the key difference between traditional and AI-based approaches:
- A traditional algorithm follows rules written by a programmer. A spam filter might be told: "If an email contains these exact phrases, move it to spam."
- A machine learning algorithm is given thousands of emails already labeled "spam" or "not spam." It finds the patterns that distinguish them on its own, including patterns no one thought to write down.
The result of that learning process is called a model. The learning algorithm is the method. The model is what the method produces. Once trained, the model is used to make predictions about new examples, such as whether an email that just arrived is spam.
Machine learning algorithms learn by repeatedly adjusting the model to reduce its mistakes, a process called optimization. For more on how that learning works, see What Is Machine Learning?.
Algorithm vs AI
An algorithm is any step-by-step procedure. AI is a field of computer systems that perform tasks associated with human intelligence, such as understanding language or recognizing images. AI systems are built from algorithms, but most algorithms have nothing to do with AI.
| Algorithm | AI | |
|---|---|---|
| What it is | A set of steps for solving a problem | Systems that perform tasks associated with human intelligence |
| How the steps are set | Usually written by a person | Often learned from data |
| Scope | Includes recipes, sorting methods and arithmetic procedures | A specific field within computing |
| Example | A calculator adding two numbers | A photo app recognizing faces |
| Relationship | Algorithms are the building blocks | AI systems use many algorithms |
Many modern AI systems use a structure called a neural network, loosely inspired by the brain. What Is a Neural Network? explains how those work, and How Does AI Work? shows how the pieces fit together.
Why algorithms matter
Algorithms increasingly shape decisions that affect people's lives: which job applications get a closer look, which transactions get flagged as possible fraud, which news stories you see and what price you are offered.
Knowing what an algorithm is helps you ask better questions about those decisions:
- What information does it use? An algorithm can only work with the inputs it receives.
- Who designed it, and for what goal? A feed designed to maximize time spent will behave differently from one designed to show recent posts first.
- If it learned from data, what data? Patterns in past data, including unfair ones, can carry into a model's predictions. The glossary entry on bias covers this.
- Can a person review or challenge the result?
Common misconceptions about algorithms
"Algorithms are always computer code." Any precise, step-by-step procedure is an algorithm, including one written on paper or followed from memory.
"Algorithms are neutral." Algorithms follow the goals, rules and data chosen by the people who build them. Those choices shape the results.
"An algorithm and an AI model are the same." In machine learning, the algorithm is the learning method, and the model is the trained result that makes predictions.
Related AI terms
- Algorithm: the short LATHIC Glossary definition
- Model: what a machine learning algorithm produces after training
- Machine learning: the approach that lets computers learn patterns from data
- Optimization: the process of adjusting a model to reduce its errors
- Training: teaching a model by showing it examples
Frequently Asked Questions
What are algorithms on social media?
Social media algorithms are the ranking and recommendation systems that choose what appears in your feed and in what order. They predict what you are likely to engage with, using signals such as what you have liked, shared, watched or commented on, and details about the content and the account that posted it.
Which is an example of an algorithm?
A recipe is a classic example. It starts with ingredients (the input), follows ordered steps that include decisions and waiting (the process), and ends with a finished dish (the output). On a computer, the method a navigation app uses to calculate the fastest route is another.
What are the 5 steps of an algorithm?
There is no single official list of five steps. A widely used list of five features comes from computer scientist Donald Knuth: finiteness (it ends), definiteness (every step is precise), input, output and effectiveness (every step can actually be carried out). When designing an algorithm, people typically define the problem, identify inputs and outputs, write the steps, test them and refine.
What does algorithm mean?
An algorithm is a precise procedure that reaches a result in a limited number of clearly defined steps. The word is named after al-Khwarizmi, a Persian mathematician who lived in the 800s.
What is an AI algorithm?
An AI algorithm is a procedure used to build or run an AI system. The most common type is a machine learning algorithm, which learns patterns from example data rather than following rules written for every case. The result of that learning is a model, which can then make predictions about new information.
Sources
- Encyclopaedia Britannica, "Algorithm." https://www.britannica.com/science/algorithm
- Merriam-Webster, "algorithm." https://www.merriam-webster.com/dictionary/algorithm
- Donald E. Knuth, The Art of Computer Programming, Vol. 1, Section 1.1 "Algorithms" (InformIT excerpt). https://www.informit.com/articles/article.aspx?p=2221792
- Encyclopaedia Britannica, "Euclidean algorithm." https://www.britannica.com/science/Euclidean-algorithm
- Meta (Nick Clegg), "How AI Influences What You See on Facebook and Instagram," June 29, 2023. https://about.fb.com/news/2023/06/how-ai-ranks-content-on-facebook-and-instagram/
- Instagram (Adam Mosseri), "Instagram Ranking Explained," May 31, 2023. https://about.instagram.com/blog/announcements/instagram-ranking-explained/
- TikTok Newsroom, "How TikTok recommends videos #ForYou," June 18, 2020. https://newsroom.tiktok.com/en-us/how-tiktok-recommends-videos-for-you
- YouTube, "How YouTube Works: Recommendations." https://www.youtube.com/howyoutubeworks/recommendations/
- European Commission, "The Digital Services Act." https://digital-strategy.ec.europa.eu/en/policies/digital-services-act