Introduction to Algorithms
intermediate25 minLearning objectives
- Define an algorithm
- Explain the characteristics of an effective algorithm
- Distinguish between algorithms and programs
- Evaluate algorithms for correctness and efficiency
Learn
AQA 4.3.1 — What is an algorithm?
Retrieval: the Dictionaries lesson promised a real comparison between linear search's step-by-step scanning and a dictionary's near-instant lookup. Before that comparison can be rigorous, this sequence needs shared vocabulary for talking about algorithms precisely — that's what this lesson builds.
An algorithm is a precise, step-by-step sequence of instructions for solving a problem or completing a task, written independently of any particular programming language. A program is one specific implementation of an algorithm, written in a particular language — the same algorithm could be implemented as a Python program, a Java program, or even followed by hand on paper.
Characteristics of an effective algorithm
- Unambiguous — each step has exactly one clear meaning, not several possible interpretations.
- Finite — it must eventually terminate, not run forever.
- Correct — it actually produces the right result for every valid input, not just the inputs you happened to test.
- Efficient — it should not use dramatically more time or memory than the problem genuinely requires.
Common mistake
Treating "algorithm" and "program" as interchangeable. You can describe the same algorithm (e.g. "check every item until you find a match, or reach the end") in structured English, in a flowchart, in pseudocode, or in Python — the algorithm is the underlying method; the program is just one written-down form of it. This distinction matters because AQA can ask you to design, trace or evaluate an algorithm without writing any code at all.
Worked example — evaluating an algorithm for correctness
Algorithm: "To find the largest number in a list, look at the first number
and assume it is the largest. Then check the second number - if it's bigger,
that becomes the new largest. Repeat for every remaining number."
Is this correct? Trace it against [3, 7, 2, 9, 4]: assume 3 is largest → compare 7, bigger, now 7 is largest → compare 2, not bigger → compare 9, bigger, now 9 is largest → compare 4, not bigger → final answer 9. Correct. Is it efficient? It looks at every number exactly once, which is the minimum possible for this problem — so yes, this algorithm is both correct and efficient.
Challenge — spot the flaw
Algorithm: "To find the largest number in a list, look at the first two
numbers and keep the bigger one. Repeat for the rest of the list, two
numbers at a time."
Trace this against a list with an odd number of items, such as [3, 7, 2, 9, 4]. Does it still work correctly? Identify exactly where the algorithm breaks down, and explain why "look at the characteristics before you trust an algorithm" matters even when a method sounds reasonable at first glance.
Extension
Write your own algorithm, in plain structured English, for an everyday process (making a hot drink, getting ready for school, checking out at a shop) — then evaluate it against all four characteristics above, honestly noting any it doesn't fully satisfy.
Looking ahead: the next two lessons (Flowcharts, then Pseudocode) give you two more precise, standard ways to represent an algorithm like the ones above — a skill you'll use for the rest of the course.