A-level Computing/AQA/Paper 1/Theory of computation/Halting problem





Halting Problem
Very early on in modern computing, a British academic named Alan Turing devised the halting problem. This problem is to do with whether we can determine if a program will ever come to a halt or run for ever, for example: Would write hello to the screen then stop. However, take a look at: This would never finish, it would never come to a halt as x will always be larger than 8 and never get any smaller. This means the while loop will continue for ever, constantly printing out "hello". In the two cases shown it is easy to tell if a program will halt or not, but it isn't so easy for all programs. Imagine we get a more complex piece of code:

This is harder but still solvable taking a little more thinking and a little time on the processor. We could get a piece of code that takes weeks, years or even thousands of years to finish. But how can we know that all programs will end or not? To determine whether the program halts we: Surely we create a mathematical proof to determine whether code will end or not I hear you say. Well let's prove just the opposite:
 * run a program with a given input, if it stops we know it stops
 * BUT if it keeps running beyond a reasonable amount of time we cannot conclude that it will loop for ever (maybe we need to wait a little longer...)





Let us create a program K that will loop forever if the result of H is to halt, and halt if the result of H is to loop for ever:



We can therefore see that there are examples of programs such as K that we cannot determine whether they are ever going to halt.


 * Read more on the halting problem