Virtual laboratory/Mathematics/Graph theory/The halting problem (Turing) — the limits of computers

The halting problem (Turing) — the limits of computers

An extension of the topic of computability (computer science). No program exists that, for any other program, decides whether it will halt or run forever — some things are fundamentally uncomputable. Alan Turing proved this in 1936, defining a model of the computer (the Turing machine) along the way.

The halting problem (Turing) — the limits of computers
Mathematics · Graph theory · The halting problem (Turing) — the limits of computers (1936)
Analysed program PPProgram A → HALTS
A: for i in 1..100: print(i)
Can you write a single program that, for EVERY other program, decides whether it halts?
program P
A
verdict
HALTS
number of steps
100
detector H
does not exist
🎯 Challenge: true or false?
streak: 0

I’ll give you a statement about the halting problem — decide whether it is true. Key: a general halting detector CANNOT be built.

What just happened?

For program A (“count to 100”) you can see at once that it halts. For program B (“while true”) — that it runs forever. But for program C (“search for a counterexample to some hypothesis”) it is unknown: if a counterexample exists, the program finds it and stops; if none exists — it searches forever. And we cannot tell in advance which case holds.

The halting problem

This is a fundamental result of theoretical computer science, proved by Alan Turing in 1936 — in the very paper that defined the Turing machine, a mathematical model of a computer. The question is: can you write a single universal program (a detector HH) that, for ANY other program PP and its input, decides whether PP ever halts or runs forever?

H(P,x)={1if P(x) halts0if P(x) runs ∞H(P, x) = \begin{cases} 1 & \text{if } P(x) \text{ halts} \\ 0 & \text{if } P(x) \text{ runs } \infty \end{cases}

Proof by contradiction (self-reference)

Turing proved that such an HH does not exist. The proof is ingenious and contrarian — in the spirit of Russell’s paradox. Suppose HH exists. Let us build from it a contrarian program DD that does the OPPOSITE of what the detector claims:

D(P)={loop ∞if H(P,P)=1STOPif H(P,P)=0D(P) = \begin{cases} \text{loop} \ \infty & \text{if } H(P,P) = 1 \\ \text{STOP} & \text{if } H(P,P) = 0 \end{cases}

Now let us run DD on itself — D(D)D(D):

H(D,D)=1  ⟺  D(D) does not halt  ⟺  H(D,D)=0H(D,D) = 1 \iff D(D) \text{ does not halt} \iff H(D,D) = 0

We obtain a self-contradiction: if the detector claims that D(D)D(D) halts, then DD deliberately enters a loop (does not halt) — and vice versa. Since the assumption that HH exists leads to a contradiction, such a program cannot exist. The halting problem is UNDECIDABLE (undecidable).

What does it mean in practice?

The consequence is profound: there are problems that are fundamentally uncomputable — that no computer, however infinitely fast, will ever solve. It is not a matter of “too little power”, but a fundamental limit on what algorithms can achieve. That is why you cannot write a program that perfectly detects all viruses, all bugs in someone else’s code or all infinite loops.

Why this matters for your exams:

Turing’s discovery — alongside Gödel’s incompleteness theorems — mapped out the limits of mathematics and computer science, and at the same time laid the foundations of all computing (Turing is regarded as its father). This extends the topic of computability: the very scheme of proof by contradiction and the diagonal argument (self-reference) are classic tools of logic and set theory.

Remember: there are algorithmically undecidable problems — no program solves the halting problem for all possible programs. It is not a lack of computing power, but a hard, mathematical limit of computability.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

The halting problem

There is no algorithm HH that, for an arbitrary program PP and its input, decides whether PP halts or runs forever.

Proof by contradiction

If HH existed, you could build a program DD that does the “opposite” of what HH predicts for DD run on itself — a contradiction (self-reference, as in Gödel).

Conclusion

There are uncomputable problems — no algorithm solves them, regardless of the computer's power (Turing, 1936).

Notation: HH a hypothetical halting detector, PP the program under test, DD a program that fools HH.

Frequently asked questions

›

Can you check, for every program, whether it will halt?

No — the halting problem is undecidable, as Alan Turing proved in 1936.

›

What does the undecidability proof rest on?

On a contradiction: if a halting detector existed, you could build a program that fools it (self-reference).

›

What does “uncomputable” mean?

That there are problems no algorithm will solve, regardless of the computer's power.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →