Intermediate Topic 31 of 51 Theory & Discrete Math
Halting Problem
Undecidable question of whether a program terminates.
How it works
The halting problem asks whether a given program will eventually stop or run forever on a given input. Alan Turing proved in 1936 that no algorithm can decide it for all program-input pairs. The proof uses diagonalization: assuming a halting decider H, construct a program D that runs H on its own description and does the opposite of what H predicts, giving a contradiction. The halting set is recognizable but not decidable.
Step-by-step walkthrough
- Suppose a program H could tell whether any program halts.
- Build D which asks H about itself and does the opposite.
- Run D on its own code.
- If H says D halts, D loops, and if H says it loops, D halts.
- Contradiction, so no such H can exist.
Where it is used
It explains why perfect bug detectors, infinite-loop checkers, optimal compilers and general program equivalence checkers cannot exist, and it is the standard starting point for reductions that show other problems are undecidable.
Common pitfall
It does not mean we cannot analyze any programs; many restricted or specific programs can be proven to terminate, and timeouts give practical approximations. Misunderstanding it as no tool can find any loop is wrong. The impossibility applies to a single algorithm that works on all programs. Termination analysis tools target subclasses.
Where it fits in the course
Halting Problem is topic 31 of 51 in Theory & Discrete Math, rated Intermediate. It follows Decidability. The next topic is Reductions.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Theory & Discrete Math quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Theory & Discrete Math quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Halting Problem?
Where do people use Halting Problem?
What is the most common mistake with Halting Problem?
What should I learn before this topic?
How can I practice it?
Is Halting Problem hard to learn?
How long does it take to learn Halting Problem?
Which topics are related to Halting Problem?
What should I study after Halting Problem?
Related topics
- Decidability (Theory & Discrete Math)
- Reductions (Theory & Discrete Math)
- Church-Turing Thesis (Theory & Discrete Math)
- Rice's Theorem (Theory & Discrete Math)
- Consensus Problem (Distributed Systems & Cloud)
- Knapsack Problem (Algorithms)
- ABA Problem (Concurrency & Parallelism)