ArticleslgStudy

computer science

Halting problem

Halting problem is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Halting problem rather than just read about it. In short: In computability theory, the halting problem is the decision problem of, given an arbitrary computer program and an input, determining whether said program will eventually finish running and halt, or will continue to run forever. Alan Turing proved in 1937 that the halting problem is undecidable, meaning that no general algorithm exists that can correctly solve the problem for all possible program–input pairs.

Key takeaways

  • Halting problem belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Halting problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Halting problem from memory before moving on to harder problems.

Reference excerpt

In computability theory, the halting problem is the decision problem of, given an arbitrary computer program and an input, determining whether said program will eventually finish running and halt, or will continue to run forever. Alan Turing proved in 1937 that the halting problem is undecidable, meaning that no general algorithm exists that can correctly solve the problem for all possible program–input pairs. The problem comes up often in discussions of computability since it demonstrates that some functions are mathematically definable but not computable. A key part of the formal statement of the problem is a mathematical definition of a computer and program, usually via a Turing machine. The proof then shows, for any program f that might determine whether programs halt, that a "pathological" program g exists for which f makes an incorrect determination. Specifically, g is the program that, when called with some input, passes its own source and its input to f and does the opposite of what f predicts g will do. The behavior of f on g shows undecidability as it means no program f will solve the halting problem in every possible case.

Background The halting problem is a decision problem about properties of computer programs on a fixed Turing-complete model of computation. This model of computation includes all programs in Turing-equivalent programming languages. Given a program and an input, the question is whether the program will eventually halt when run with that particular input. In this abstract framework, there are no limitations on the memory or time required for the program's execution; the program may run arbitrarily long and consume arbitrarily large amounts of storage before halting. For example, in pseudocode, the program

while (true) continue never halts; rather, it goes on forever in an infinite loop. By contrast,

print "Hello, world!" halts immediately after printing. Simple cases like these are easy to decide, but more complex programs are not. Turing proved no algorithm exists that always correctly decides whether, for a given arbitrary program and input, the program halts when run with that input. The essence of Turing's proof is that any such algorithm can be made to produce contradictory output and therefore cannot be correct.

Programming consequences Most subroutines are intended to finish. The fact that the halting problem is undecidable is often naively taken to mean that establishing whether a program halts is impossible. However, programs such as the T2 Temporal Prover could automatically establish that certain Windows device-driver dispatch routines will always eventually return. It appears feasible that "future program-termination proof tools [may] work 99.9% of the time on programs written by humans." Some infinite loops can be quite useful. For instance, event loops are typically coded as infinite loops. In total functional programming languages these are often encoded using corecursion, as functions that process and produce infinite coinductive data types such as streams. This formalism allows proving a dual termination property known as productivity. In hard real-time computing, subroutines must not only finish, but finish before a given deadline. In order to meet these requirements, programmers apply the rule of least power and use restricted styles, not quite fully Turing-complete, that make it easy to prove that the resulting subroutines finish before the given deadline. These include languages such as MISRA C, SPARK, and Rocq.

Common pitfalls The halting problem requires a decision procedure that works for all programs and inputs. But for any specific program and input, the answer is simply "halts" or "does not halt". Consider two simple decision procedures, one that always answers "halts" and another that always answers "does not halt". For any given case, one of these two algorithms answers correctly, yet neither algorithm solves the halting problem. Interpreters are programs that simulate the execution of programs whatever source code they are given. Such programs can demonstrate that a program does halt, by running the program for some number of steps. However, an interpreter will not halt if its input program does not halt, so this approach cannot solve the halting problem as stated; it does not successfully answer "does not halt" for programs that do not halt, or determine whether a program will eventually halt or run forever. The halting problem is decidable for linear bounded automata (LBAs) or deterministic machines with finite memory. Such a machine has finitely many possible configurations, so any deterministic program on it must eventually either halt or repeat a previous configuration:

...any finite-state machine, if left completely to itself, will fall eventually into a perfectly periodic repetitive pattern. The duration of this repeating pattern cannot exceed the number of internal states of the machine... However, Minsky notes:

...the magnitudes involved should lead one to suspect that theorems and arguments based chiefly on the mere finiteness [of] the state diagram may not carry a great deal of significance. For example, a computer with a million two-state components would have at least 21,000,000 possible states:

This is a 1 followed by about three hundred thousand zeroes ... Even if such a machine were to operate at the frequencies of cosmic rays, the aeons of galactic evolution would be as nothing compared to the time of a journey through such a cycle. For nondeterministic finite automata (restricted to finite memory), it is also decidable whether the machine halts on none, some, or all of the possible sequences of nondeterministic decisions, by enumerating states after each possible decision.

History

In April 1936, Alonzo Church published his proof of the undecidability of a problem in the lambda calculus. Turing's proof was published later, in January 1937. Since then, many other undecidable problems have been described, including the halting problem which emerged in the 1950s.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Halting problem

Start with the simplest possible case. Write down what Halting problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Halting problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Halting problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Halting problem

In research
Halting problem appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Halting problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Halting problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1936 introductions, Computability theory, Mathematical problems, so understanding it makes those chapters shorter.
In everyday life
Look for Halting problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Halting problem” →

How to study Halting problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Halting problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Halting problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Halting problem in simple terms?

In computability theory, the halting problem is the decision problem of, given an arbitrary computer program and an input, determining whether said program will eventually finish running and halt, or will continue to run forever. Alan Turing proved in 1937 that the halting problem is undecidable, m…

Why does Halting problem matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Halting problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Halting problem.

Tags

  • 1936 introductions
  • Computability theory
  • Mathematical problems
  • Theory of computation
  • Undecidable problems

Keep exploring