Fundamentals of algorithms
An algorithm is a precise, step-by-step set of instructions that solves a problem in a finite number of steps. Algorithms are the heart of computer science — every program is ultimately the execution of one or more algorithms.
Why algorithms matter
Before writing a single line of code, a programmer designs an algorithm. A well-designed algorithm:
- Solves the problem correctly for all valid inputs
- Terminates (does not run forever)
- Is efficient — uses as few steps and as little memory as possible
Key topics in this section
Representing algorithms (CS1.1)
Algorithms can be expressed in three ways:
- Pseudocode — structured English using programming constructs (IF, WHILE, FOR)
- Flowcharts — diagrams with standard symbols (start/stop, process, decision, I/O)
- Written descriptions — plain English numbered steps
No single representation is always best; the choice depends on audience and context.
Efficiency (CS1.2)
We compare algorithms by counting the number of steps they take. For a list of n items:
- A simple scan through the list takes proportional to n steps — manageable for small lists
- An algorithm that compares every pair takes proportional to n² steps — quickly becomes unacceptably slow
Recognising why one algorithm is more efficient than another is a core GCSE skill.
Searching algorithms (CS1.3)
Two algorithms for finding an item in a list:
| Algorithm | Precondition | Typical steps |
|---|---|---|
| Linear search | None | Up to n steps |
| Binary search | List must be sorted | Up to log₂(n) steps |
Binary search repeatedly halves the search space; linear search checks each item in turn.
Sorting algorithms (CS1.4)
Two algorithms for ordering a list:
| Algorithm | Method | Efficiency |
|---|---|---|
| Bubble sort | Repeatedly swap adjacent items | O(n²) — slow for large lists |
| Merge sort | Divide list in half, sort each half, merge | O(n log n) — much faster |
Bubble sort is simple to trace; merge sort is more efficient but harder to implement.
Common exam skills
- Trace through an algorithm step by step, showing variable states
- Identify the number of comparisons or swaps in a given pass
- Explain why one algorithm is more or less efficient than another
- Write short algorithms in AQA pseudocode or as a flowchart
Algorithm design principles
A correct algorithm must:
- Have clearly defined inputs and outputs
- Be unambiguous — every step has one clear meaning
- Terminate — must end after a finite number of steps
- Be correct — produces the right output for every valid input
These principles apply whether the algorithm is written in pseudocode, a flowchart or a programming language.
AI-generated · claude-opus-4-7 · v3-deep-computer-science