Getting Started
We often think of computers as machines capable of solving any problem, given enough time and processing power. However, computer science has proven that this is not the case. There are entire classes of problems that are well-defined and seem straightforward, yet are provably impossible for any computer, now or in the future, to solve perfectly. This chapter explores these fundamental limits of computation.
What You Should Be Able to Do
Define a decision problem and provide an example.
Explain the difference between a decidable problem and an undecidable problem.
Describe the Halting Problem as a famous example of an undecidable problem.
Explain why the existence of undecidable problems represents a fundamental limit on computing.
Key Concepts & Application
The Core Idea
In computing, an algorithm is a finite sequence of well-defined instructions to solve a problem. We rely on algorithms to sort lists, search for data, and perform complex calculations. For most problems, we assume that if we are clever enough, we can design an algorithm to solve it.
The surprising truth is that some problems have no algorithmic solution. These are not just "hard" problems that take a long time to solve; they are problems for which it is logically impossible to create an algorithm that gives a correct answer for every possible input.
Imagine a librarian who wants to create a master catalog of all books that do not mention themselves in their own text. The librarian then considers creating a special book, "The Catalog of All Books That Do Not Mention Themselves." The question then arises: should this new catalog be listed within its own pages?
If it is listed, it violates the rule, because it now mentions itself.
If it is not listed, it fits the rule (a book that doesn't mention itself) and therefore should be listed.
This is a paradox. The very existence of such a catalog creates a logical contradiction. Undecidable problems in computer science are rooted in this same kind of self-referential paradox.
Logic & Application
To understand undecidable problems, we first need to categorize problems based on their answers.
A decision problem is a problem that can be answered with a simple "yes" or "no."
Example: "Is the number 10 an even number?" (Yes)
Example: "Does the list
[5, 8, 12]contain the number 7?" (No)
A decidable problem is a decision problem for which an algorithm can be written that will always produce a correct "yes" or "no" answer in a finite amount of time, for any and all inputs. Most problems we encounter in programming are decidable.
// An algorithm for a decidable problem: Is a number even?
PROCEDURE isEven(number)
{
// The modulo operator gives the remainder of a division.
// If a number divided by 2 has a remainder of 0, it is even.
IF (number MOD 2 = 0)
{
RETURN (true) // "Yes"
}
ELSE
{
RETURN (false) // "No"
}
}
- An undecidable problem is a decision problem for which it is impossible to construct an algorithm that will always provide a correct "yes" or "no" answer for every possible input.
The most famous example is the Halting Problem.
The Halting Problem: "Given an arbitrary program and an input, will that program eventually stop (halt), or will it run forever in an infinite loop?"
This seems like a simple "yes/no" question. However, it has been mathematically proven that no single algorithm can ever be written to answer it correctly for all possible programs and inputs.
Tracing & Analysis
To understand why the Halting Problem is undecidable, we can use a logical proof by contradiction.
Assume a Solution Exists: Let's pretend we have a magical procedure called
halts(program, input). It takes a program and its input as arguments and is guaranteed to returntrueif the program would eventually stop, andfalseif it would loop forever.Construct a Paradoxical Program: Using our magical
haltsprocedure, we can construct a new, devious procedure calledparadox. This procedure takes a single program as its input.
// Our theoretical paradoxical procedure
PROCEDURE paradox(aProgram)
{
// Step 1: Ask the magical halts procedure what aProgram
// would do if it were given itself as input.
IF (halts(aProgram, aProgram) = true)
{
// If halts() says aProgram will stop,
// we intentionally enter an infinite loop.
REPEAT UNTIL (false)
{
// This loop runs forever
}
}
ELSE
{
// If halts() says aProgram will loop forever,
// we immediately stop (halt).
RETURN
}
}
- Run the Paradox on Itself: Now for the critical question: What happens if we call
paradox(paradox)? We are feeding theparadoxprocedure its own source code as its input.
Let's trace the two possibilities:
| If paradox(paradox) eventually HALTS... - Then, according to the logic inside paradox, the IF condition halts(paradox, paradox) must have been false.
But our
haltsprocedure is supposed to be perfect! Ifparadox(paradox)actually halts,halts(paradox, paradox)should have returnedtrue.This is a contradiction.
| If paradox(paradox) runs in an INFINITE LOOP... - Then, according to the logic inside paradox, the IF condition halts(paradox, paradox) must have been true.
But again,
haltsis supposed to be perfect! Ifparadox(paradox)actually loops forever,halts(paradox, paradox)should have returnedfalse.This is also a contradiction.
Since both possibilities lead to a logical contradiction, our initial assumption—that a perfect halts procedure could exist in the first place—must be false. Therefore, the Halting Problem is undecidable.
Key Terminology & Logic
| Term | Description |
|---|---|
| Decision Problem | A problem that has a "yes" or "no" answer. |
| Decidable Problem | A decision problem that an algorithm can solve for all inputs. |
| Undecidable Problem | A decision problem for which no algorithm can ever be created. |
Core Concepts & Terminology
Algorithm: A finite set of instructions that accomplish a specific task. Algorithms are the building blocks of all computer programs.
Decision Problem: A problem that can be formulated to have a "yes" or "no" answer, such as "Is this number prime?" or "Is this list sorted?"
Decidable Problem: A decision problem for which a general algorithm can be created that is guaranteed to produce the correct yes/no answer for every possible input.
Undecidable Problem: A decision problem for which it is not possible to create an algorithm that will always provide a correct answer for all inputs. The problem is provably unsolvable by any computer.
The Halting Problem: The classic undecidable problem of determining whether any given program will eventually stop running (halt) or continue to run forever, given a specific input.
Core Skill Check
Conceptual Check: Why can't we solve the Halting Problem by just running a program and waiting to see if it stops?
Application: Is the problem "Find the shortest route between two cities on a map" a decision problem?
Analysis: If a problem is proven to be undecidable, does that mean we just haven't found the right algorithm for it yet?
Common Misconceptions & Clarifications
"Undecidable" means "unsolvable for some weird inputs."
Clarification: It means there is no single, general algorithm that can solve it for all possible inputs. While we can determine if specific, simple programs halt, we cannot create one program that does it for every conceivable program.
"Undecidable" is the same as "intractable" or "very hard."
Clarification: These are different concepts. An intractable problem is decidable (solvable), but the algorithm would take an unreasonable amount of time (e.g., billions of years) for large inputs. An undecidable problem is impossible to solve algorithmically, regardless of time.
"We just need a more powerful computer to solve it."
Clarification: The undecidability of the Halting Problem is a matter of logic, not processing power. No amount of speed or memory can overcome the fundamental paradox it creates. It is a proven limit of computation itself.
Summary
While computers are incredibly powerful tools for problem-solving, they operate within fundamental logical limits. The existence of undecidable problems demonstrates that there are questions that computation can never answer. A decision problem is one with a yes/no answer. If an algorithm can be created to solve it for all inputs, it is decidable. If it is logically impossible to create such an algorithm, as with the Halting Problem, the problem is undecidable. This concept is crucial for understanding the true boundaries of what is and is not computable.