The Halting Problem

Have you always wondered why it is impossible to decide algorithmically, given an algorithm and a (finite) input, whether or not the algorithm halts on the supplied input? This is called the halting problem, and it's officially unsolvable.

It seems strange that if you are given both the algorithm and the input (a finite number of bits), that there is no systematic procedure which can answer that elusive question: does the algorithm halt or not? Really, where can that one bit hide?

However deep and philosophical the question seems, when looking at the problem from another angle the reason it is unsolvable is actually very simple. Basically it all boils down to this: suppose we have an algorithm H which claims to solve the halting problem, then using H we can construct an algorithm and input that H is completely wrong about.

How do we actually go about constructing this new algorithm for defeating H? It's easy! First of all, we'll suppose that H always halts with a "yes" or "no" on valid algorithms (otherwise it wouldn't solve the halting problem anyway). Now we can make an algorithm D which takes as input an algorithm P and then asks H to decide if P halts on P or not. If H says "yes, P halts on P", D goes into an infinite loop (and thus does not halt). On the other hand, if H says "nope, P doesn't halt on P", then D calls it quits and halts.

Is that it? Well, let's see what we've got. We're going ask the following question: does D halt on D? First we'll ask H. Suppose H says "yes". Then from the way we constructed D we know that D goes into an infinite loop. But infinite loops don't usually halt, so H is wrong! Ok, so maybe H doesn't say "yes", maybe it says "no"! But then, by construction, D halts and H is wrong again! In other words, whether D actually halts on D or not, H doesn't know the first thing about it! And it should! So H doesn't solve the halting problem after all.

In conclusion, we used the system to beat the sytem. Knowing H we built ourselves an algorithm D so that H is always wrong on D with input D. And since we can do this with any algorithm H which claims to solve the halting problem, no such algorithm can exist.