---
title: "What Is an Algorithm? Simple Examples for Kids and Beginners"
description: "What an algorithm is, everyday examples, and three short Python programs showing why algorithms must be correct and fast, with real outputs."
slug: what-is-an-algorithm
canonical: https://learn.modernagecoders.com/blog/what-is-an-algorithm/
date: 2026-09-28
dateModified: 2026-09-28
category: "Programming"
tags: ["Algorithms", "Beginners", "Python", "Kids"]
keywords: ["what is an algorithm", "what is an algorithm for kids", "algorithm examples", "algorithm examples in everyday life", "algorithm vs program", "properties of a good algorithm", "euclid's algorithm"]
readTime: "8 min read"
author: "Modern Age Coders Team"
---
# What Is an Algorithm? Simple Examples for Kids and Beginners

> A plain-English definition, everyday examples, and three short programs that show the two questions every algorithm must answer: is it correct, and is it fast?

![What is an algorithm: an input of two numbers, three steps, and an output of their greatest common divisor](/images/blog/what-is-an-algorithm/00-hero.png)

*By Modern Age Coders Team · 2026-09-28 · 8 min read*

**Quick answer:** An algorithm is a clear, step-by-step method that takes an input and always produces the right output, like a recipe or the method for long division. Good algorithms are precise, ordered, finite, correct and efficient. Correctness comes first: a find-the-largest algorithm that starts at 0 fails on negative numbers. Efficiency comes second: halving finds a number from 1 to 100 in at most 7 guesses instead of 100, and Euclid's 2,300-year-old algorithm finds a GCD in 3 steps instead of 442 checks.

An algorithm is a clear, step-by-step method for solving a problem, precise enough that anyone following it, or any computer running it, gets the right answer every time. A recipe, the way you do long division, and the instructions a satnav uses to find a route are all algorithms. The word sounds technical, but the idea is one you already use every day.

This guide explains what makes something an algorithm, gives everyday examples, and then shows three short Python programs that reveal the two questions every algorithm has to answer: is it correct, and is it fast? One of them has a bug that looks perfectly reasonable. Every output below comes from actually running the code.

## What is an algorithm? A simple definition

An algorithm takes an **input**, follows a set of **steps**, and produces an **output**. To add two large numbers on paper, the input is the two numbers, the steps are "add the rightmost column, carry if needed, move left", and the output is the total. The steps work for any two numbers, which is what makes it an algorithm rather than a single answer.

The word itself comes from the name of Muhammad ibn Musa al-Khwarizmi, a ninth-century mathematician in Baghdad whose books on calculation were translated into Latin. His name became *algorismus*, the word for doing arithmetic with written numerals, and eventually algorithm.

![Five properties of a good algorithm: precise, ordered, finite, correct and efficient; the first three make something an algorithm, the last two make it a good one](/images/blog/what-is-an-algorithm/01-properties.png)

*Precise, ordered and finite define an algorithm. Correct and efficient make it a good one.*

## Everyday examples of algorithms

- **A recipe:** ingredients in, steps in order, a cake out. A good recipe says "bake for 25 minutes at 180 degrees", not "bake until it seems done".
- **Getting dressed:** socks before shoes. Order matters, which is one of the key properties of an algorithm.
- **Long division:** divide, multiply, subtract, bring down, repeat. Our [long division guide](/blog/long-division-step-by-step) walks through it step by step.
- **Looking up a word in a dictionary:** open near the middle, decide which half, repeat. This is the same halving idea you will see in code below.
- **A satnav finding a route,** a search engine ranking pages, a streaming app suggesting a film: these are algorithms too, just much larger.

> **Try this with a child**

> Ask them to write instructions for making a jam sandwich, then follow the instructions exactly as written, and only as written. "Put jam on the bread" might mean putting the whole jar on the loaf. It is funny, and it teaches the most important property of an algorithm faster than any definition: every step must be precise.

## Algorithm vs program: what is the difference?

An algorithm is the method. A program is that method written in a particular programming language so a computer can run it. The same algorithm can be written in Python, Java, Scratch or plain English. That is why programmers often plan an algorithm first, in words or pseudocode, before writing any code. Our post on [Python and Java](/blog/python-vs-java-which-to-learn-first) shows the same ideas written in two languages.

## Question 1: is the algorithm correct?

Here is an algorithm to find the largest number in a list. Start with a "biggest so far" of 0, look at each number, and if it is bigger, remember it. Sounds sensible. Version 2 changes one line: it starts with the first number in the list instead.

**largest.py**

```python
def largest_v1(numbers):
    biggest = 0
    for n in numbers:
        if n > biggest:
            biggest = n
    return biggest

def largest_v2(numbers):
    biggest = numbers[0]
    for n in numbers[1:]:
        if n > biggest:
            biggest = n
    return biggest

for test in ([3, 9, 4], [12, 5, 30, 8], [-4, -2, -7]):
    print(test, "v1:", largest_v1(test), " v2:", largest_v2(test))
```

**Output**

```text
[3, 9, 4] v1: 9  v2: 9
[12, 5, 30, 8] v1: 30  v2: 30
[-4, -2, -7] v1: 0  v2: -2
```

![Version 1 of find the largest starts at 0 and returns 0 for the list minus 4, minus 2, minus 7, which is wrong; version 2 starts at the first item and correctly returns -2](/images/blog/what-is-an-algorithm/02-largest-bug.png)

*Version 1 passes the easy tests and fails the one nobody thought of.*

Both versions agree on the first two lists. On a list of negative numbers, version 1 answers 0, a number that is not even in the list, because no negative number is ever bigger than its starting value of 0. Version 2 correctly answers -2. This is why correctness is the first question: an algorithm must work for *every* valid input, not just the ones you tried. Testing with unusual inputs, like negatives, zero or an empty list, is how programmers find these bugs.

## Question 2: is the algorithm efficient?

Two correct algorithms can do very different amounts of work. Think of the game where someone picks a secret number from 1 to 100 and says "higher" or "lower" after each guess. One strategy is to count up: 1, 2, 3 and so on. Another is to always guess the middle of the numbers that are still possible:

**guess.py**

```python
def count_up(secret):
    guesses = 0
    for guess in range(1, 101):
        guesses += 1
        if guess == secret:
            return guesses

def halving(secret):
    low, high, guesses = 1, 100, 0
    while True:
        guesses += 1
        guess = (low + high) // 2
        if guess == secret:
            return guesses
        if guess < secret:
            low = guess + 1
        else:
            high = guess - 1

for secret in (7, 50, 73, 100):
    print(f"secret {secret:>3}: counting up {count_up(secret):>3} guesses, halving {halving(secret)} guesses")
worst_up = max(count_up(s) for s in range(1, 101))
worst_half = max(halving(s) for s in range(1, 101))
print("worst case over all 100 secrets:", worst_up, "vs", worst_half)
```

**Output**

```text
secret   7: counting up   7 guesses, halving 6 guesses
secret  50: counting up  50 guesses, halving 1 guesses
secret  73: counting up  73 guesses, halving 6 guesses
secret 100: counting up 100 guesses, halving 7 guesses
worst case over all 100 secrets: 100 vs 7
```

![Finding the secret number 73 by halving: guesses 50, 75, 62, 68, 71 and 73 narrow the range from 1 to 100 down to one number in 6 guesses](/images/blog/what-is-an-algorithm/03-halving.png)

*Each guess throws away half of what is left.*

Both strategies always find the number, so both are correct. But counting up needs up to 100 guesses, while halving never needs more than 7. The gap grows fast: for numbers up to a million, counting up could take a million guesses, while halving needs at most 20, because 2 to the power 20 is just over a million. This halving algorithm is called **binary search**, and it is why computers can search enormous sorted lists almost instantly. Our guide to [Big O notation](/blog/big-o-notation-explained-simply) shows how programmers describe this difference precisely.

## One of the oldest algorithms still in use

Algorithms are much older than computers. Around 300 BC, the Greek mathematician Euclid described a method for finding the greatest common divisor (GCD) of two numbers, the largest number that divides both. The slow way is to try every possible divisor. Euclid's way is to divide, keep the remainder, and repeat:

**euclid.py**

```python
def gcd_by_trying(a, b):
    checks = 0
    for d in range(min(a, b), 0, -1):
        checks += 1
        if a % d == 0 and b % d == 0:
            return d, checks

def gcd_euclid(a, b):
    steps = 0
    while b != 0:
        steps += 1
        print(f"  step {steps}: {a} = {a // b} x {b} + {a % b}")
        a, b = b, a % b
    return a, steps

print("trying every number:", gcd_by_trying(1071, 462))
print("Euclid:")
print("result:", gcd_euclid(1071, 462))
```

**Output**

```text
trying every number: (21, 442)
Euclid:
  step 1: 1071 = 2 x 462 + 147
  step 2: 462 = 3 x 147 + 21
  step 3: 147 = 7 x 21 + 0
result: (21, 3)
```

![Finding the GCD of 1071 and 462: trying every number takes 442 checks, while Euclid's algorithm takes 3 steps and gives 21](/images/blog/what-is-an-algorithm/04-euclid.png)

*Same answer, a tiny fraction of the work.*

Trying every number from 462 downwards took 442 checks to reach 21. Euclid's algorithm got there in 3 steps. It is still used today, for example in the mathematics behind RSA, a widely used form of encryption. If you want to see it applied, our guide to [finding the HCF and LCM in Python](/blog/how-to-find-hcf-and-lcm-in-python) builds on it, and our post on [modular arithmetic](/blog/modular-arithmetic-explained) explains why remainders are so powerful.

## How to design your own algorithm

1. **Understand the problem.** What is the input? What should the output be? Work through one small example by hand.
2. **Write the steps in plain words.** Be as precise as the jam sandwich test demands.
3. **Test it on paper** with a normal case, then an unusual one: zero, negatives, an empty list, the largest possible value.
4. **Turn it into code** and run the same tests.
5. **Ask if it could do less work.** Only after it is correct.

That order, correct first and fast second, is how professional programmers work too. If you want a structured path from here, our guide on [how to start learning data structures and algorithms](/blog/how-to-start-learning-data-structures-and-algorithms) sets out what to learn next.

> A program is only as good as the algorithm inside it. Get the steps right, and the code is the easy part.

## How we teach it

Algorithms are where the principles on our [how we teach](/how-we-teach) page matter most: working out a method before seeing it written down, tracing code line by line until every step can be predicted, and seeing the same problem solved more than one way, just as this post compares counting up with halving. Younger learners can meet algorithms through our [Scratch classes](/scratch-coding-classes-for-kids), and older students through Python, one to one or in small groups of 5 to 10.

[Book a free class](/book-demo) [Book a priority demo](/book-demo)

## Frequently asked questions

**What is an algorithm in simple words?**

An algorithm is a clear, step-by-step method for solving a problem. It takes an input, follows precise steps in order, and always finishes with an output. A recipe and the method for long division are everyday examples.

**What is an example of an algorithm for kids?**

Making a jam sandwich, getting dressed, or brushing your teeth are good examples, because the steps must happen in the right order. A fun activity is to write sandwich instructions and have someone follow them exactly as written.

**What is the difference between an algorithm and a program?**

An algorithm is the method, and a program is that method written in a programming language so a computer can run it. The same algorithm can be written in Python, Java, Scratch or plain English.

**What are the properties of a good algorithm?**

It should be precise, with each step having one meaning; ordered; finite, so it always finishes; correct for every valid input; and efficient, doing no more work than necessary.

**Where does the word algorithm come from?**

It comes from the name of Muhammad ibn Musa al-Khwarizmi, a ninth-century mathematician in Baghdad. Latin translations of his books on calculation turned his name into algorismus, which became algorithm.

**What is the oldest algorithm?**

Euclid's algorithm for the greatest common divisor, described around 300 BC, is one of the oldest algorithms still in everyday use. Methods for arithmetic from ancient Babylon and Egypt are older still.

**Do you need to be good at maths to understand algorithms?**

No. Algorithms are about clear, logical steps, and you can learn them with everyday examples before any maths is involved. Working with algorithms often improves maths skills, not the other way round.

---

*Source: https://learn.modernagecoders.com/blog/what-is-an-algorithm/*
