What Is an Algorithm?
Explore the concept of an algorithm including its definition, origin, and why it is crucial in programming. Understand the three core properties of a good algorithm: correctness, efficiency, and clarity, and learn through the example of a linear search algorithm in Python how these principles apply to solving problems systematically.
What an algorithm actually is
The term “algorithm” is derived from the name of the ninth-century Persian mathematician Muhammad ibn Musa al-Khwarizmi, whose work formalized systematic mathematical procedures. Today, algorithms are fundamental to modern software systems.
An algorithm is a finite, well-defined sequence of steps that takes some input, processes it through a series of instructions, and produces an output. Every algorithm terminates. Every step is unambiguous. And the same input always produces the same output.
Consider this analogy:
A recipe is an algorithm. It takes inputs (ingredients), applies a precise sequence of steps (chop, mix, bake for exactly 30 minutes), and produces an output (a finished dish). It is finite, unambiguous, and deterministic. The same ingredients and the same steps produce the same result every time. That is exactly what an algorithm does in code.
What makes an algorithm good
Not every sequence of steps qualifies as a good algorithm. Three properties define what to aim for:
Correctness
The algorithm must produce the right answer for every valid input. A fast algorithm that returns wrong results is not just useless; it is actively harmful. Correctness comes before everything else.
Efficiency
The algorithm must use resources economically. Time and memory both count. An algorithm that works but takes a year to finish is no more practical than one that never finishes. Efficiency is quantified using time and space complexity analysis, which you will study in depth moving forward.
Clarity
Each step must be unambiguous. A well-written algorithm can be understood, verified, and translated into any programming language by any competent programmer, and it will produce identical results. If you cannot explain each step clearly, the algorithm is probably not fully understood yet.
Priority order matters: Correctness comes first, always. An efficient but incorrect algorithm is worthless. Clarity comes second. An algorithm nobody can read or maintain creates long-term costs. Efficiency is optimized last, and only when measurements show that it is needed.
Linear search, step by step
One of the simplest algorithms is linear search. Given a list and a target value, determine whether the target is in the list.
Before writing code, it helps to write out the logic in plain language:
Linear search in plain English:
Start at the first element. Compare it to the target. If they match, return the current index and stop. If not, move to the next element. If you reach the end without finding a match, return “not found.”
Now, apply the same logic in Python:
Next, let's look at a demo of how linear search runs:
Major categories of algorithms
Algorithms are categorized by the approach used to solve a problem. Recognizing which category a problem belongs to is a key problem-solving skill. It narrows the set of applicable strategies.
Pattern recognition is the skill: When you see a new problem, the key question is which category it belongs to. Recognizing that “find the shortest path” is a graph problem or that “generate all combinations” calls for recursion immediately tells you which algorithm family to draw from. That instinct is what this course builds.