Skip to content
Happy Programming Guide
Start learning
Programming Basics

What Is an Algorithm? Explained Without the Maths

An algorithm is just a clear set of steps for getting something done. Here is what that means in code, why some solutions are faster than others, and how to design one.

An algorithm is a clear set of steps for getting something done. A recipe is an algorithm. Directions to a friend’s house are an algorithm. In programming, it is the plan your code follows.

The word sounds academic. The idea is not.

An algorithm you already know#

Finding a name in a paper phone book. You do not start at page one. You open near the middle, see whether the name comes before or after, and throw away half the book. Then you repeat.

That is binary search, and it is one of the most useful algorithms in computing. You worked it out without being taught, because it is obvious once the data is sorted.

The same job, two plans#

Say you need to find a number in a list. Plan A checks every item from the start:

Python
def linear_search(numbers, target):
    for index, value in enumerate(numbers):
        if value == target:
            return index
    return -1

Plan B assumes the list is sorted and halves the search each time:

Python
def binary_search(numbers, target):
    low = 0
    high = len(numbers) - 1

    while low <= high:
        middle = (low + high) // 2
        if numbers[middle] == target:
            return middle
        if numbers[middle] < target:
            low = middle + 1
        else:
            high = middle - 1
    return -1

Both give the right answer. On a list of 1,000,000 items, Plan A might check a million values. Plan B needs about twenty. That gap is the entire point of studying algorithms.

Why speed is described with “Big O”#

You will see notation like O(n) and O(log n). It is a rough label for how the work grows as the data grows — not a measurement in seconds.

Notation Means Example
O(1) Same effort regardless of size Reading list[0]
O(log n) Work grows very slowly Binary search
O(n) Double the data, double the work Looping once through a list
O(n²) Double the data, four times the work A loop inside a loop

You do not need this for your first programs. It starts mattering when your data gets large or an interviewer asks.

How to design an algorithm before you code#

Most beginners open the editor too early. Try this order instead:

  1. Say the problem in one sentence. “Find the highest score in a list.”
  2. Do it by hand with tiny data. Take [4, 9, 2] and notice what your brain actually did.
  3. Write the steps in plain words. Assume the first is the highest. Compare each of the rest. If one is bigger, remember that instead.
  4. Translate to code. Now the typing is the easy part.
  5. Test the awkward cases. Empty list? One item? All the same?
Python
def highest(scores):
    if not scores:
        return None

    best = scores[0]
    for score in scores:
        if score > best:
            best = score
    return best

Which ones are worth learning early?#

You do not need to memorise a textbook. These give you the most understanding per hour:

  • Linear search — the honest starting point
  • Binary search — teaches you why sorted data is valuable
  • Counting and summing in a loop — used constantly in real work
  • Sorting — mainly so you understand what the built-in sort is doing for you

In real projects you will use the built-in sort rather than writing your own. Knowing roughly how it works is still useful when something is slow.

Questions people ask#

Do I need to be good at maths?

For everyday programming, no. Algorithm work uses logic and careful thinking far more than formulas. Some specialised fields need real mathematics; web apps, scripts and automation mostly do not.

What is the difference between an algorithm and a data structure?

An algorithm is the plan; a data structure is how the information is arranged. They affect each other — binary search only works because the list is sorted first.

Should I grind coding challenge sites?

They are useful for interview practice and terrible as a first way to learn. Build a few real things first, then use puzzle sites to sharpen specific skills. See how to practise programming.

Where to go next#

Try it for realBeginner programming projects worth finishing

Keep reading

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *