What is an Algorithm? Definition, Examples

#Math Terms
TL;DR
An algorithm is a finite, well-defined sequence of instructions that solves a specific problem or performs a computation. The word comes from al-Khwarizmi, a 9th-century Persian mathematician whose name was Latinised as Algoritmi.
BT
Bhanzu TeamLast updated on May 15, 20267 min read

What Is an Algorithm?

An algorithm is a finite, ordered sequence of unambiguous steps that produces a specific output from a given input. The key properties:

  1. Finite β€” terminates after a finite number of steps.

  2. Well-defined β€” each step is unambiguous; no guessing.

  3. Input/output β€” takes specified input(s) and produces specified output(s).

  4. Effective β€” each step can actually be performed.

Algorithms predate computers by thousands of years. The long-division algorithm you learned in school is an algorithm. So is following a recipe, looking up a word in a dictionary, or finding your way home using turn-by-turn directions.

Where Does the Word "Algorithm" Come From?

The word algorithm comes from a person's name. In the 9th century CE, the Persian polymath Muhammad ibn Musa al-Khwarizmi worked at the House of Wisdom in Baghdad β€” the great library of the Abbasid Caliphate. Around 820 CE, he wrote a book on Hindu-Arabic numerals and computational methods. When translated into Latin in the 12th century, his name became Algoritmi, and the title Algoritmi de numero Indorum ("Al-Khwarizmi on the Hindu numerals") became the source of the modern word algorithm.

The same al-Khwarizmi gave us the word algebra from his other major work Al-Jabr. Two words from one mathematician β€” algorithm and algebra β€” both running everything from school math to modern computing.

What Are the Most Famous Algorithms in Math?

Euclidean Algorithm (GCD)

Find the greatest common divisor of two integers. Step:

  1. Divide the larger by the smaller; note the remainder.

  2. Replace the larger with the smaller; replace the smaller with the remainder.

  3. Repeat until the remainder is 0. The previous remainder is the GCD.

Example. Find GCD(48, 18):

$$48 = 2 \times 18 + 12$$ $$18 = 1 \times 12 + 6$$ $$12 = 2 \times 6 + 0$$

GCD = 6.

First described in Euclid's Elements (c. 300 BCE) β€” the oldest still-used algorithm in the world.

Sieve of Eratosthenes (Primes)

Find all prime numbers up to a limit $N$.

  1. List the integers from 2 to $N$.

  2. Take the smallest unmarked number β€” it's prime.

  3. Cross out all multiples of that prime.

  4. Repeat with the next unmarked number.

  5. The unmarked numbers at the end are all primes.

Named after Eratosthenes of Cyrene (c. 276–c. 194 BCE).

Long Division Algorithm

Standard step-by-step procedure for dividing one multi-digit number by another. The most-practised algorithm in elementary school math.

Newton's Method (Root Finding)

Find a numerical root of an equation $f(x) = 0$:

$$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$

Each iteration approaches a root quadratically. Used in calculators, financial software, and scientific computing.

What Are the Types of Algorithms?

In modern math and computer science, algorithms are classified by what they do.

Type

What It Does

Example

Searching

Find an item in a collection

Binary search

Sorting

Order items by some criterion

Quicksort, Merge sort

Numerical

Compute with numbers

Newton's method, FFT

Graph

Solve problems on graphs/networks

Dijkstra's shortest path

Encryption

Protect data

RSA, AES

Compression

Reduce data size

ZIP, JPEG, MP3

Machine learning

Learn patterns from data

Gradient descent

Greedy

Make locally optimal choices

Huffman coding

Divide and conquer

Break problem into subproblems

Mergesort, FFT

Recursive

Define solution in terms of smaller cases

Factorial, Fibonacci

Why Does the Algorithm Concept Matter? (The Real-World GROUND)

"Computer science is no more about computers than astronomy is about telescopes." β€” Edsger Dijkstra, 1986.

Algorithms run the modern world. Every interaction with a computer involves dozens or hundreds of algorithms running quietly in the background:

  • Google Search. PageRank algorithm (and its successors) rank billions of web pages by relevance β€” built on linear algebra and graph theory.

  • GPS routing. Dijkstra's shortest-path algorithm (1959) computes your driving route in milliseconds.

  • Online shopping recommendations. Collaborative filtering algorithms suggest items based on similarity to other users.

  • Credit card fraud detection. Machine-learning algorithms flag unusual transactions in real time.

  • Spotify and Netflix. Recommendation algorithms decide what plays next.

  • MRI scans and CT scans. The reconstruction of 3D images from cross-section measurements uses the filtered back-projection algorithm.

  • Cryptocurrencies. Every Bitcoin transaction is verified by the SHA-256 hash algorithm.

  • Air-traffic control. Conflict-detection and resolution algorithms keep aircraft safely separated.

  • DNA sequencing. Algorithms align billions of DNA reads against reference genomes.

  • Weather forecasting. Numerical weather prediction algorithms simulate the atmosphere on supercomputers.

The 20th-century theorist Alan Turing formalised what exactly counts as an algorithm in his 1936 paper on computability β€” defining the Turing machine as the abstract model of any algorithmic computation. The Turing machine is the theoretical basis of every computer that exists today.

A Worked Example

Find GCD(60, 48) using the Euclidean algorithm.

The intuitive (wrong) approach. A student tries to find common factors by listing them all:

Factors of 60: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60. Factors of 48: 1, 2, 3, 4, 6, 8, 12, 16, 24, 48. Common: 1, 2, 3, 4, 6, 12. GCD = 12.

This works but takes forever for larger numbers (try GCD(1071, 462) by listing).

Why the algorithm is faster. The Euclidean algorithm needs at most a few divisions β€” even for huge numbers, it terminates in $O(\log n)$ steps.

The correct method (Euclidean algorithm).

$$60 = 1 \times 48 + 12$$ $$48 = 4 \times 12 + 0$$

GCD = 12. Two divisions instead of listing 12 factors of each number.

Check. $12 \times 5 = 60$ and $12 \times 4 = 48$ β€” 12 divides both βœ“.

At Bhanzu, our trainers teach algorithms by showing the slow brute-force way first, then the algorithmic shortcut. Once a student feels the savings, they understand why algorithms are valued β€” not just what they are.

What Are the Most Common Mistakes With Algorithms?

Mistake 1: Confusing an algorithm with its implementation

Where it slips in: Treating the steps of long division as the algorithm, vs. one written-out solution of a specific problem.

Don't do this: Calling "23 Γ· 7" itself an algorithm.

The correct way: The long-division procedure β€” the general step-by-step method β€” is the algorithm. Applying it to "23 Γ· 7" is running the algorithm. The algorithm is the recipe; the worked example is dinner.

Mistake 2: Skipping the termination condition

Where it slips in: Iterative algorithms (Euclidean, Newton's method) require a stopping condition. Forgetting it means the algorithm never ends.

Don't do this: Run the Euclidean algorithm forever without checking "remainder is 0."

The correct way: Every iterative algorithm needs an explicit terminate when X condition. Without one, the algorithm doesn't terminate β€” and is therefore not a valid algorithm by definition.

Mistake 3: Confusing algorithm with heuristic

Where it slips in: Some procedures find good answers but not guaranteed answers β€” those are heuristics, not algorithms.

Don't do this: Calling a strategy that usually works an algorithm.

The correct way: An algorithm produces a correct answer for every valid input. A heuristic produces a good answer often. ChatGPT-style large language models are heuristic search procedures, not algorithms in the strict sense.

The Mathematicians Who Shaped Algorithms

Muhammad ibn Musa al-Khwarizmi (c. 780–c. 850, Persia/Baghdad) β€” His Latinised name Algoritmi gave us the word algorithm. His 9th-century book on computation with Hindu-Arabic numerals introduced systematic algorithmic methods to Europe.

Euclid of Alexandria (c. 325–c. 265 BCE, Greek Egypt) β€” His Elements contained the Euclidean algorithm for the GCD β€” the oldest algorithm still in active use today.

Alan Turing (1912–1954, England) β€” Formalised the concept of an algorithm in his 1936 paper On Computable Numbers, introducing the Turing machine as the abstract model of computation. The foundation of all modern computer science.

A Practical Next Step

Try these three before moving on to programming and data structures.

  1. Use the Euclidean algorithm to find GCD(84, 36).

  2. List the prime numbers from 2 to 30 using the Sieve of Eratosthenes.

  3. Apply the long-division algorithm to compute $237 \div 8$.

Was this article helpful?

Your feedback helps us write better content

Frequently Asked Questions

What is an algorithm in simple words?
An algorithm is a finite, step-by-step recipe for solving a specific problem. Each step is unambiguous, the procedure terminates after a finite number of steps, and it produces a specific output from a given input.
Who invented the algorithm?
The concept goes back to ancient Sumerian and Greek mathematicians, but the word algorithm comes from al-Khwarizmi (9th century CE Persia/Baghdad). The modern definition was formalised by Alan Turing in 1936.
What are some examples of algorithms?
The Euclidean algorithm (find GCD), the Sieve of Eratosthenes (find primes), long division, Newton's method (find roots), binary search, mergesort, Dijkstra's shortest path, RSA encryption, JPEG compression, and Google PageRank.
What are the main types of algorithms?
Searching, sorting, numerical, graph, encryption, compression, machine-learning, greedy, divide-and-conquer, recursive, and dynamic-programming algorithms. Each type fits a particular kind of problem.
Is a recipe an algorithm?
Roughly yes β€” a cooking recipe is a finite sequence of unambiguous steps producing a specific output. The "algorithm" definition just requires more precision in each step. Real algorithms must be unambiguous to the point that a computer can execute them.
What's the difference between an algorithm and a program?
An algorithm is the abstract step-by-step idea. A program is the concrete implementation of an algorithm in a specific programming language. The same algorithm (mergesort, say) can be implemented as a program in Python, C++, JavaScript, or any other language.
Why are algorithms important in everyday life?
Algorithms run almost every digital interaction you have: Google search results, GPS routing, social media feeds, online recommendations, medical imaging, banking transactions, and machine learning. Each is a different algorithm working in the background.
✍️ Written By
BT
Bhanzu Team
Content Creator and Editor
Bhanzu’s editorial team, known as Team Bhanzu, is made up of experienced educators, curriculum experts, content strategists, and fact-checkers dedicated to making math simple and engaging for learners worldwide. Every article and resource is carefully researched, thoughtfully structured, and rigorously reviewed to ensure accuracy, clarity, and real-world relevance. We understand that building strong math foundations can raise questions for students and parents alike. That’s why Team Bhanzu focuses on delivering practical insights, concept-driven explanations, and trustworthy guidance-empowering learners to develop confidence, speed, and a lifelong love for mathematics.
Related Articles
Book a FREE Demo ClassBook Now β†’