Turing machines, computability & the halting problem

Computer Science · Theory of computation

Question 1 of 10

0

    Can an algorithm be written that decides, for every program and every input, whether that program will halt?

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Turing machines, computability & the halting problem explained

    A Turing machine is an abstract model of computation proposed by Alan Turing in 1936. It has an infinite tape divided into cells, a read/write head that sits on one cell, a finite set of states, and a table of rules. At each step the machine reads the symbol under the head, then, based on its current state and the rule, writes a symbol, moves the head one cell left or right, and changes state. Despite its simplicity, a Turing machine can carry out any calculation that a modern computer can carry out, given enough time and tape. The Church-Turing thesis states that this is the limit of what is computable, though it is a claim about intuition rather than something that has been proved.

    A problem is computable if some algorithm always gives the right answer. The halting problem asks whether a given program, run on a given input, will eventually stop or run forever. Turing proved in 1936 that no general algorithm can answer this for every program and input.

    Worked example

    Suppose a program halts(P, x) existed that always correctly returns true if program P halts on input x, and false otherwise. Build a new program D that takes a program P as input.

    1. Call halts(P, P), which asks whether P halts when given its own text as input.
    2. If the answer is true, D loops forever. If the answer is false, D halts immediately.

    Now run D with its own text as input. If halts(D, D) is true, D loops forever, so the answer was wrong. If halts(D, D) is false, D halts, so the answer was wrong again. Both cases are impossible, so halts cannot exist.

    What you will practise

    92 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • What does the infinite tape of a Turing machine provide?
    • What are the main parts of a Turing machine?
    • According to the Church–Turing thesis, which claim is made?
    • Can an algorithm be written that decides, for every program and every input, whether that program will halt?
    • A decision problem is decidable when:
    • What is a universal Turing machine?
    • What determines the next action of a Turing machine at each step?
    • When does a Turing machine halt?

    …and 84 more.