CSC 396 · Automata theory, Computability and Formal Languages
Our notes
2 min readDecidable and recognisable
- A language is decidable (recursive) if some Turing machine always halts and correctly says yes or no.
- It is recognisable (recursively enumerable) if some machine says yes for every member, but may run forever on non-members.
Examples of decidable problems: does a DFA accept a given string? Is a DFA's language empty? Does a CFG generate a given string (CYK)?
The halting problem
Problem: given a program P and input w, does P halt on w?
Theorem (Turing, 1936): no algorithm solves it for all P and w.
Proof by contradiction (diagonalisation):
- Suppose a program H(P, w) always halts and answers correctly.
- Build D(P): run H(P, P); if H says "halts", loop forever; if it says "loops", halt.
- Ask what D(D) does. If D(D) halts, H said it loops, so it loops. If it loops, H said it halts, so it halts. Either way, a contradiction.
- So H cannot exist.
Other undecidable problems (by reduction)
If solving problem A would let us solve the halting problem, A is undecidable too. Examples:
- Does a program ever print "hello"?
- Are two context-free grammars equivalent?
- Is a CFG ambiguous?
- Rice's theorem: every non-trivial question about what a program computes (its behaviour, not its text) is undecidable.
Practical meaning: no tool can perfectly detect all viruses or prove every program bug-free; real tools give approximate answers.
Complexity: P and NP
Decidable is not enough; we want fast answers.
- P: problems solvable in polynomial time (n, n², n³ steps): sorting, shortest paths, checking if a number is prime (AKS, 2002).
- NP: problems whose solutions can be checked in polynomial time: given a proposed timetable, it is quick to check no clashes; finding one may be hard.
- NP-complete: the hardest problems in NP (Cook-Levin theorem, 1971: Boolean satisfiability). If any one is in P, all of NP is. Examples: travelling salesman (decision form), graph colouring (exam timetabling), knapsack, scheduling.
- P = NP? is the most famous open question in computer science (a Clay Millennium Prize problem, unsolved as of 2026).
Worked example: why exponential is hopeless
Checking every route for a travelling salesman visiting 20 cities: (20 − 1)!/2 ≈ 6.1 × 10¹⁶ routes. At 10⁹ routes a second, about 6.1 × 10⁷ seconds, nearly two years. Real solvers use clever search and good-enough approximations.
Exams usually ask
- Distinguish decidable and recognisable languages.
- State and prove the undecidability of the halting problem.
- Define P, NP and NP-complete with examples.
Common mistake
Thinking undecidable means "very hard". It means no algorithm exists at all, however fast the computer; hard (NP-complete) problems have algorithms that are just slow.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.