← Back to subjects
⭐ 0
AQA A-level Computer Science (7517) Β· Theory of computation
Mini-Lesson

Theory of computation

This mini-lesson covers AQA 4.4 β€” Theory of computation: the deepest and most beautiful part of the course. It asks not how to solve a problem but whether it can be solved at all β€” and if so, in a usable time

  • Abstraction, automation and information hiding
  • Finite state machines β€” with and without output
  • Regular expressions and regular languages
  • Backus-Naur Form β€” defining syntax formally
  • Turing machines, the halting problem and computability
  • Tractable vs intractable problems

Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect ⭐ stars. Press Start when you're ready.

4.4 Β· Abstraction

Abstraction and automation

Abstraction is the removal of unnecessary detail so that the essence of a problem can be reasoned about. AQA distinguishes several kinds:

  • Representational abstraction β€” a model that deliberately throws detail away. The London Underground map is topologically right and geographically wrong, and that is why it works.
  • Abstraction by generalisation β€” grouping things by shared characteristics (a superclass in OOP).
  • Procedural abstraction β€” a subroutine you can call without knowing how it works inside.
  • Functional abstraction β€” you care only about the mapping from input to output.
  • Data abstraction β€” an ADT defined by its operations, not its storage.
  • Information hiding β€” implementation detail is deliberately inaccessible, so it can change without breaking anything.

Automation is putting an abstraction to work: you build a model of a real system and then simulate it β€” a flight simulator, a climate model, a queueing model of a supermarket. The model is only ever as good as the abstraction it rests on.

4.4 Β· FSMs

Finite state machines

A finite state machine (FSM) is a machine with a finite set of states, one start state, a set of accepting states, and transitions that fire on an input symbol.

  • An FSM without output (a finite state automaton) simply accepts or rejects the input string.
  • An FSM with output (a Mealy machine) also emits an output symbol on each transition, written input / output.

An FSM can be drawn as a state transition diagram or written as a state transition table.

S0S1S2 11 00 accepting state
This FSM accepts any string over {0,1} containing at least two 1s. Zeros loop; each 1 advances a state.

The limit of an FSM: it has finite memory β€” the current state is all it remembers. So it cannot count without bound. No FSM can recognise the language aⁿbⁿ (n a's followed by exactly n b's), because it would need unlimited memory to remember how many a's it has seen. That limit is precisely why we need Turing machines.

Calculate

Your turn β€” trace the FSM

1Using the FSM above (start S0; a 1 moves you on one state, a 0 loops on the spot; S2 is the only accepting state), feed it the string 0 1 0 0 1 0. Type ACCEPT or REJECT.
Hint: Zeros do nothing. Count the 1s: how many do you need to reach S2?
4.4 Β· Regular languages

Regular expressions

A regular expression is a compact way of describing a set of strings β€” a regular language. The key result: a language is regular if and only if some FSM accepts it. Regular expressions and finite state machines have exactly the same power.

SymbolMeaningExample
|either / ora|b matches a or b
*zero or moreab* matches a, ab, abb, abbb…
+one or moreab+ matches ab, abb… but not a
?zero or oneab? matches a and ab only
( )grouping(ab)* matches "", ab, abab…

Useful set notation goes with this: ∈ (member of), βˆͺ (union), ∩ (intersection), βŠ† (subset), βˆ… (empty set), and the Cartesian product A Γ— B of all ordered pairs.

Real use: regular expressions drive the lexical analysis stage of every compiler β€” the tokeniser that recognises identifiers, numbers and keywords is, literally, a finite state machine built from regular expressions.

Calculate

Your turn β€” counting strings

2How many distinct strings of length 4 can be formed over the alphabet {0, 1}?
strings
Hint: Each of the 4 positions can independently be one of 2 symbols.
Quick check

The limits of an FSM

?Why can no finite state machine recognise the language aⁿbⁿ (n a's followed by exactly n b's, for any n)?
4.4 Β· BNF

Backus-Naur Form

Backus-Naur Form (BNF) is a formal metalanguage for defining the syntax of a language. Compilers use it in the syntax analysis stage.

<digit> ::= 0|1|2|3|4|5|6|7|8|9 <letter> ::= a|b|c| ... |z <number> ::= <digit> | <digit><number> <variable> ::= <letter> | <letter><variable>

Read ::= as "is defined as" and | as "or". Symbols in <angle brackets> are non-terminals (defined elsewhere); everything else is a terminal.

The crucial feature is recursion: <number> is defined partly in terms of itself, which lets a finite set of rules describe an infinite set of valid numbers.

Why BNF beats regular expressions: BNF can express nested, balanced structure β€” matching brackets, nested IF statements β€” which no regular expression can. BNF describes context-free languages, a strictly larger class than the regular languages. A syntax diagram (railroad diagram) shows the same rules pictorially.

Quick check

BNF

?Given <number> ::= <digit> | <digit><number>, what does the recursive second alternative achieve?
4.4 Β· Turing machines

Turing machines and computability

A Turing machine is the formal model of computation. It has:

  • an infinite tape divided into cells, each holding one symbol from a finite alphabet;
  • a read/write head positioned over one cell;
  • a finite set of states, with a start state and halting states;
  • a transition function β€” given (current state, symbol read) it writes a symbol, moves the head left or right, and changes state.

That is all. Yet the Church-Turing thesis holds that anything that can be computed by any effective procedure can be computed by a Turing machine. A universal Turing machine takes the description of another Turing machine on its tape and simulates it β€” the theoretical ancestor of the stored-program computer.

computable = "a Turing machine exists for it"

Language hierarchy: FSM (regular) βŠ‚ pushdown automaton (context-free) βŠ‚ Turing machine (recursively enumerable). Each machine adds memory: none β†’ a stack β†’ an infinite tape.

4.4 Β· Limits

The halting problem

Some problems are non-computable: no algorithm can exist for them, however clever the programmer and however fast the computer.

The halting problem asks: given any program and any input, decide whether that program will eventually halt or run forever. Turing proved in 1936 that no algorithm can do this for all cases.

The proof, in outline (by contradiction):

  • Suppose a program H(P, I) exists that returns True if P halts on input I, and False otherwise.
  • Build a new program D(P): it calls H(P, P). If H says "halts", D deliberately loops forever. If H says "loops", D halts.
  • Now ask: what does D(D) do? If D(D) halts, then by its own construction it must loop. If D(D) loops, then it must halt.
  • Both cases are contradictions. So H cannot exist. ∎

It is not a limit of technology. No future computer, no quantum machine, no amount of memory changes this. It is a limit of computation itself β€” and it is why no compiler can ever warn you about every infinite loop.

Quick check

The halting problem

?Which statement about the halting problem is correct?
4.4 Β· Classification

Tractable and intractable problems

Even among computable problems, some are useless in practice. AQA divides them by the complexity of the best known algorithm:

  • Tractable β€” a solution exists in polynomial time: O(1), O(log n), O(n), O(n log n), O(nΒ²), O(nΒ³)… These scale.
  • Intractable β€” the best known algorithm is worse than polynomial: O(2ⁿ), O(n!). A solution exists in theory but not in a usable time for realistic n.
nn²2ⁿn!
101001 0243 628 800
204001 048 576β‰ˆ 2.4 Γ— 10¹⁸
502 500β‰ˆ 1.1 Γ— 10ΒΉβ΅β‰ˆ 3.0 Γ— 10⁢⁴

Because intractable problems must still be dealt with, we use a heuristic: a rule of thumb that finds a good enough answer quickly, with no guarantee of optimality. Nearest-neighbour for the travelling salesman, and the estimate function inside A*, are both heuristics.

Calculate

Your turn β€” why exponential growth kills

3An algorithm runs in O(2ⁿ) time and takes exactly 1 second when n = 10. Assuming the run time doubles with each increase of 1 in n, how many seconds does it take when n = 20?
seconds
Hint: Going from n = 10 to n = 20 means 10 doublings. Work out 2^10.
Calculate

Your turn β€” brute-force TSP

4A brute-force travelling salesman solver starts at a fixed city and tries every possible order of visiting the remaining cities. With 6 cities in total, how many different tours must it try?
tours
Hint: The start is fixed, so you are permuting the other 5 cities: that is 5 factorial.
Quick check

Tractability

?A problem is described as intractable. What does this mean?
Sort it

Classify the problems

Tap a problem, then tap the group it belongs to.

βœ… Tractable

🐌 Intractable

🚫 Non-computable

Match it

Match the term to its meaning

Tap an item on the left, then its partner on the right.

Meaning
Term
Recap

The big ideas to know

Abstraction: representational Β· generalisation Β· procedural Β· functional Β· data Β· information hiding

FSM: finite states + transitions; accepts regular languages only; cannot count without bound

Regex: | * + ? ( ) β€” regular expressions and FSMs have exactly the same power

BNF: ::= and | Β· non-terminals in angle brackets Β· recursion gives infinite languages Β· beats regex on nesting

Turing machine: infinite tape + head + finite states; Church-Turing thesis; universal TM = stored program

Halting problem: proved undecidable by contradiction β€” a limit of computation, not of hardware

Tractability: tractable = polynomial Β· intractable = exponential/factorial Β· use heuristics

That is the whole of AQA 4.4. Press Finish to see your score.

πŸ†

Mini-lesson complete!

⭐⭐⭐

You've worked through Theory of computation for AQA A-level Computer Science (7517). πŸŽ‰

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

πŸ“£ Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

β†’ Back to all subjects