What Is an Algorithm?
An algorithm is a finite, ordered set of well-defined steps for solving a problem or completing a task. Here is what that means and how algorithms are used.
An algorithm is a finite, ordered set of well-defined steps for solving a problem or carrying out a task. Given some input, it describes precisely how to work towards a result, one step at a time, until it finishes. Although the word is now closely associated with computers, the concept is much older and much broader: any clear, repeatable procedure that reliably reaches a definite outcome can be called an algorithm.
A precise recipe for solving a problem
A helpful everyday comparison is a cooking recipe. It lists ingredients (the inputs), sets out steps in a fixed order, and ends with a finished dish (the output). A good recipe leaves little room for confusion: each instruction is clear enough that different cooks following it carefully will produce broadly the same result. An algorithm works the same way, except the steps operate on data rather than food, and they must be defined with even greater precision.
The term itself derives from the name of the ninth-century Persian scholar al-Khwarizmi, whose works on arithmetic introduced systematic methods of calculation to a wide audience. Long before electronic computers, mathematicians used algorithms for tasks such as finding the greatest common divisor of two numbers or performing long division. What computers added was the ability to carry out such procedures automatically, at enormous speed and scale.
What makes something an algorithm
Computer scientists usually expect an algorithm to have a few defining properties. It should have a clear input and a clear output. Each step should be unambiguous, so there is no doubt about what to do next. It should be made of a finite number of steps and should terminate — that is, it must eventually stop rather than run forever. And for any valid input, it should produce the correct result.
These requirements distinguish a genuine algorithm from a vague set of guidelines. “Make the website faster” is a goal, not an algorithm. “Sort this list of names into alphabetical order by repeatedly comparing neighbouring pairs and swapping them when they are out of order” describes an actual procedure with defined steps that can be followed exactly.
Everyday examples
Algorithms are everywhere in computing, often working invisibly. Common categories include:
- Sorting — arranging items into order, such as putting search results, emails or spreadsheet rows into sequence.
- Searching — finding a particular item within a collection, for example locating a word in a dictionary or a record in a database.
- Routing — working out an efficient path, as a navigation app does when planning a journey or as a network does when moving data.
- Encryption — transforming information so that only authorised parties can read it, a foundation of end-to-end encryption and of everyday security online.
Many familiar features rest on algorithms too, from the ranking that decides which results a search engine shows first to the recommendations a streaming service makes. In each case, an algorithm takes some input — a query, a viewing history — and produces an output according to defined rules.
Measuring how good an algorithm is
Two different algorithms can solve the same problem, yet one may be far more practical. Computer scientists compare algorithms mainly by their efficiency: how the resources they need grow as the input gets larger. Time complexity describes how the number of steps increases with the size of the input, while space complexity describes how much memory is required. These are often expressed using “big O” notation, a shorthand for the rate of growth.
The distinction matters enormously at scale. An approach that checks every possible combination might be fine for ten items but hopeless for ten million, because the work grows too quickly. A cleverer algorithm that reduces the number of comparisons can turn an impossible task into an instant one. This is why the study of algorithms sits at the heart of computer science.
Why algorithms matter
Algorithms are the logical core of every program. Software written in any language ultimately carries out algorithms, and the same underlying procedure can be implemented in many different ways. Understanding them helps explain how computers accomplish complex tasks reliably, and why some problems are easy for machines while others remain hard.
The idea also connects to broader questions about how computers work. The instructions an algorithm defines are eventually executed by hardware under the management of the operating system’s kernel, and the languages used to express algorithms, including those that style and script the web, all rely on the same principle: turning a well-defined sequence of steps into a dependable result.