The definition
An algorithm is a step-by-step procedure for solving a specific problem, defined precisely enough that a computer (or anyone) can follow it without making judgement calls.
The "without judgement" part is the key. A cooking recipe might say "season to taste" — that requires human judgement, not an algorithm. An algorithm has no such gaps. Every step is unambiguous. Every decision is explicit. Anyone (or any machine) following the same algorithm with the same input produces the same output.
That's the whole concept. The word can sound mysterious — the "Twitter algorithm," the "YouTube algorithm" — but it just means "the rules the system follows," which are entirely deterministic given the inputs.
A concrete example
Suppose you want to sort a list of numbers in ascending order. Here's one algorithm (insertion sort):
For each position i from 1 to the end of the list:
Let x = the value at position i
Let j = i - 1
While j >= 0 and the value at position j is greater than x:
Move the value at position j into position j+1
j = j - 1
Place x at position j+1
That's it. If you follow these steps exactly, on any starting list, you'll end up with a sorted list. There's no ambiguity. No subjective choices.
Translated into actual programming language (Python):
def insertion_sort(lst):
for i in range(1, len(lst)):
x = lst[i]
j = i - 1
while j >= 0 and lst[j] > x:
lst[j+1] = lst[j]
j = j - 1
lst[j+1] = x
The algorithm and the program both describe the same procedure. The Python version is just the algorithm written in a syntax a Python interpreter can execute.
What counts as a problem
Algorithms can solve almost anything that's well-defined:
Sorting. Put a list in order. Many algorithms exist: bubble sort, insertion sort, merge sort, quick sort, heap sort. Each has different speed/memory tradeoffs.
Searching. Find a specific item in a collection. Linear search (check each item) is slow but works on any list. Binary search is much faster but requires the list to be sorted. Hash-table lookup is essentially instant for many problem sizes.
Routing. Find the shortest path from A to B in a network. Dijkstra's algorithm is the classic; A* is a faster variant that uses heuristics. Google Maps uses sophisticated variants of these.
Compression. Take a file and represent it using fewer bits. ZIP uses Lempel-Ziv. JPEG uses discrete cosine transform plus quantization. AV1 uses motion estimation plus all the above.
Cryptography. Algorithms that encrypt, decrypt, sign, and verify data. (See how encryption actually works.)
Pattern matching. Find all occurrences of a pattern in a text. Used in your text editor's "Find" feature, in search engines, in DNA analysis.
Optimization. Find the best of many possibilities. Used in shipping logistics, scheduling, machine learning training.
Machine learning. Algorithms that find patterns in data. Linear regression, decision trees, neural network training. (See the AI cluster.)
Each is a problem, and dozens to hundreds of algorithms exist for each. Computer scientists invent new algorithms (or prove existing ones optimal) regularly.
Why algorithms are measured by efficiency
For a given problem, multiple algorithms can give the right answer. The interesting question becomes: which is faster?
Computer scientists use big O notation to describe how an algorithm's runtime grows with input size. Some common patterns:
- O(1) — constant time. Doesn't depend on input size. (Looking up a hash table.)
- O(log n) — logarithmic. Doubling the input slightly more work. (Binary search.)
- O(n) — linear. Doubling input doubles the work. (Looking through every item.)
- O(n log n) — almost linear. (Merge sort, quicksort.)
- O(n²) — quadratic. Doubling input quadruples the work. (Naive comparison of every pair of items.)
- O(2ⁿ) — exponential. Doubling input squares the work. (Brute-force trying every possibility — usually catastrophic for large inputs.)
For small inputs, the differences barely matter. For large inputs, they matter enormously. A linear algorithm on a million items runs in seconds; a quadratic algorithm on the same million items runs in years.
This is why "is your algorithm O(n) or O(n²)?" matters in programming interviews and real engineering. A 10x speed improvement is nice; an O(n²) → O(n log n) improvement is the difference between "feasible" and "impossible" at scale.
Why algorithms are everywhere now
You're using algorithms constantly without thinking about it:
- Web search. When you search, Google's algorithms (ranked under "PageRank" historically, vastly more complex now) decide which results to show.
- Social media. Twitter, Instagram, TikTok all have algorithms deciding what to show you. The mathematics is largely machine learning, but rooted in algorithm design.
- GPS. Your map app uses shortest-path algorithms (Dijkstra variants) to compute routes.
- Encryption. Every HTTPS connection uses algorithms (AES, RSA, elliptic-curve) to protect data.
- Compression. Every video you watch is decompressed by algorithms.
- Spam filters. Your email's spam classification uses machine-learning algorithms.
- Autocomplete. Algorithms predict what you mean to type.
- Online dating. Matching algorithms (variants of stable-matching algorithms) suggest profiles.
- Trading. Most stock trades are placed by algorithms, not humans.
When pundits warn about "algorithmic bias" or "the algorithm doesn't show me X," they're talking about specific programs running on specific data — concrete things that can be analysed and improved.
What an algorithm isn't
It's worth distinguishing algorithms from related things:
An algorithm is not a black box. It's a precisely-defined procedure. You can read it, understand it, debug it, change it. The "black box" feeling around modern AI is mostly because the algorithms involve millions of parameters that no human can intuitively grasp — but the underlying training algorithms are well-defined.
An algorithm is not always intelligent. A web request being routed through routers isn't "intelligent"; it's a simple rule applied many times. Many algorithms that look impressive (chess engines pre-2010, search engines pre-LLMs) are basically clever rule applications, not anything we'd call cognition.
An algorithm is not arbitrary. It's a sequence of specific steps. If you can describe what should happen step by step, you have an algorithm.
An algorithm is not always right. The output depends on inputs and the algorithm's design. A correct sorting algorithm gives a correct sort. But a "Twitter ranking algorithm" gives the answer that ranks well by Twitter's chosen metrics — which may not match your intuition about what should be ranked highly.
A famous algorithm: Euclid's GCD
Around 300 BCE, Euclid described an algorithm for finding the greatest common divisor of two numbers. The steps:
To find gcd(a, b):
If b is 0, return a (the GCD is a).
Otherwise, return gcd(b, a mod b).
That's it. The procedure is guaranteed to terminate and produce the correct answer for any pair of positive integers.
Example: gcd(48, 18):
- gcd(48, 18) → gcd(18, 48 mod 18 = 12)
- gcd(18, 12) → gcd(12, 18 mod 12 = 6)
- gcd(12, 6) → gcd(6, 12 mod 6 = 0)
- gcd(6, 0) → 6
GCD is 6. The algorithm is older than the printing press, and we still teach it because it works perfectly and exemplifies what an algorithm is.
If you'd like a guided 5-minute course on algorithms and their analysis, NerdSip can generate one.
The takeaway
An algorithm is a precise, unambiguous procedure for solving a problem. Computers can only execute things that are algorithms in this strict sense — every step must be specified. Algorithms power search, routing, compression, encryption, machine learning, and essentially everything else in computing. Efficiency matters as much as correctness; big O notation describes how an algorithm scales with input size. The word can sound mysterious in marketing copy, but underneath it just means "the rules the system follows," which are entirely concrete and analyzable.