01 / 21
?

Undecidable
Problems

Explore the fundamental limits of computation: problems that no algorithm can ever solve for every possible input.

AP Computer Science Principles

What Is a Decision Problem?

A decision problem is any problem that asks a yes-or-no question about some input. Given an input, the goal is to determine whether the answer is "yes" or "no."

✓ Example
"Is \( n \) a prime number?" Given any integer \( n \), the answer is always yes or no.
✓ Example
"Does string \( s \) contain the letter 'a'?" Again, the answer is definitively yes or no.

Decidable vs. Undecidable

A decision problem is decidable if an algorithm exists that produces a correct yes/no answer for every possible input in a finite amount of time. If no such algorithm can exist, the problem is undecidable.

Decidable
An algorithm always halts and gives the correct answer for every input.
Undecidable
No algorithm can correctly answer yes or no for all possible inputs.

Why Does This Matter?

Understanding undecidability reveals the fundamental boundaries of what computers can do. It shapes how we design software, verify programs, and think about automation.

1
Software reliability: We cannot build a universal bug-detector that catches every error in every program.
2
Security: Perfect malware detection for all programs is impossible in general.
3
AI limits: No AI system can solve every possible decision problem: there are inherent limits to machine intelligence.

The Halting Problem

The most famous undecidable problem asks: given any program \( P \) and any input \( I \), will \( P \) eventually stop (halt) when run on \( I \), or will it run forever?

Program P + Input I Halting Analyzer? ? Halts Loops No such analyzer can exist!

Proof by Contradiction

The halting problem is proved undecidable using a proof by contradiction. Assume a halting analyzer H exists, then construct a program that forces H to give the wrong answer.

1
Assume: A function halts(P, I) exists that returns true if \( P \) halts on \( I \), and false otherwise.
2
Construct: A new program Contrary(P) that calls halts(P, P). If it returns true, Contrary loops forever. If false, Contrary halts.
3
Ask: Does Contrary(Contrary) halt? Either answer leads to a contradiction.
4
Conclude: Our assumption was wrong. halts(P, I) cannot exist.

The Contradiction Visualized

Contrary(Contrary) halts(Contrary, Contrary)? returns true Contrary loops But halts said it halts! ✕ returns false Contrary halts But halts said it loops! ✕ Both paths lead to contradiction

Undecidable vs. Intractable vs. Unsolvable

Decidable Intractable Undecidable
Algorithm exists? Yes Yes No
Always gives correct answer? Yes Yes Impossible
Runs in reasonable time? Usually No (too slow) N/A
Example "Is \( n \) even?" Traveling Salesman Halting Problem

More Undecidable Problems

The halting problem is not the only undecidable problem. Many important questions about programs are also undecidable:

Equivalence
Do two programs produce the same output for every possible input?
Rice's Theorem
Any non-trivial property about a program's behavior is undecidable.
Post Correspondence
Given pairs of strings, can you arrange them so the top and bottom concatenations match?

How to Identify Undecidable Problems

1
Look for universality: Does the problem ask about all possible programs or all possible inputs?
2
Check for behavioral questions: Does it ask about what a program does (its output or behavior) rather than its syntax (structure)?
3
Try to reduce: Can you show that solving this problem would also solve the halting problem?
4
Check for contradiction: If you assume a solver exists, does a self-referential argument produce a contradiction?

Example: A Decidable Problem

Problem: "Given a list of numbers, is every element positive?"

def all_positive(numbers): for n in numbers: if n <= 0: return False return True

Example: An Undecidable Problem

Problem: "Given any program \( P \), does \( P \) produce output 42 for at least one input?"

Program P (arbitrary) Infinite possible inputs 42? ? Cannot check infinitely many inputs! This is undecidable (by Rice's Theorem)

Example: A Tricky Borderline Case

Problem: "Does this specific, known program halt on input 5?"

Specific instance
For one fixed program and one fixed input, the answer is either yes or no: it is decidable in principle.
General version
For any arbitrary program and any arbitrary input, no single algorithm works: this is undecidable.

What Can We Do?

Even though some problems are undecidable, computer scientists have practical strategies:

1
Approximate: Use heuristics that work correctly for most inputs, even if not all (e.g., virus scanners).
2
Restrict: Limit the types of programs or inputs you consider to make the problem decidable.
3
Detect when stuck: Set timeouts or resource limits and report "unknown" when the algorithm cannot decide.
4
Human assistance: Involve humans in the loop for cases the algorithm cannot resolve automatically.

Common Mistakes

✕ "Undecidable means unsolvable for any input"
Undecidable means no single algorithm solves all inputs. Individual instances may still have answers.
✕ "Just run it and see"
If a program loops forever, running it will never give you an answer. You cannot distinguish "still running" from "will run forever."
✕ "Faster computers solve undecidable problems"
Undecidability is about logical impossibility, not speed. No amount of computing power helps.

Summary Table

Question Decidable? Why?
Is \( n \) even? Yes Simple check: \( n \bmod 2 = 0 \)
Is a list sorted? Yes Compare adjacent elements
Does program \( P \) halt on input \( I \)? No Halting problem (Turing, 1936)
Do two programs produce the same output? No Reduces to halting problem
Is the shortest path \( < k \)? Yes Graph algorithms solve it
Does \( P \) ever output 0? No Rice's Theorem

Question 1 of 5

A decidable problem is one where:

Question 2 of 5

Which of the following best describes the halting problem?

Question 3 of 5

A student says: "If we just get a faster computer, we can solve the halting problem." What is wrong with this reasoning?

Question 4 of 5

Which of the following problems is decidable?

Question 5 of 5

In the proof that the halting problem is undecidable, what role does the "Contrary" program play?