5.2 Limits of Computing: Unsolvable Problems, Intractability, and Heuristics
Key Takeaways
- Alan Turing proved in 1936 that no algorithm can decide, for every program and input, whether the program will eventually halt; this is the halting problem.
- A problem is undecidable when no algorithm can solve every instance; it is intractable when an algorithm exists but needs impractically much time or memory as inputs grow.
- A heuristic is a rule of thumb that finds a good solution quickly but does not guarantee the best, or any, correct solution.
- Heuristics are useful when an exact method is too slow, when a good-enough answer is acceptable, or when a decision must be made in real time.
- At one billion operations per second, 2⁶⁰ steps take about 36.5 years, which shows why exponential algorithms fail for even moderate n.
What this competency asks
ETS asks you to be familiar with the limitations of computing in terms of time, space, and solvability, as well as with the use of heuristic solutions that can address these limitations. Beyond identifying linear, quadratic, exponential, and logarithmic growth (Section 5.1), you should be able to:
- Recognize the existence of problems that cannot be solved by a computer.
- In context, identify the factors that prevent a problem from being solvable.
- Identify situations where heuristic solutions are useful.
- In context, identify space and time limitations of computational solutions.
Problems no computer can solve
A problem is decidable if some algorithm always produces a correct yes-or-no answer in finite time for every input. A problem is undecidable if no such algorithm can exist, no matter how fast the computer or how clever the programmer.
The halting problem
The best-known undecidable problem is the halting problem: given any program and any input, determine whether the program will eventually stop or run forever. Alan Turing proved in 1936 that no algorithm can solve it for all programs.
The intuition is a proof by contradiction:
- Suppose a procedure
halts ( program, input )always correctly answers true or false. - Build a new program
trouble ( p )that callshalts ( p, p ). If the answer is true,troubleloops forever. If the answer is false,troublestops. - Now ask what happens when you run
trouble ( trouble ). Ifhaltssays it halts, it loops forever. Ifhaltssays it loops forever, it halts. Either wayhaltsis wrong. - So the assumed procedure cannot exist.
Practical consequences follow. No tool can examine every possible program and correctly report whether it contains an infinite loop, whether two programs always produce the same output, or whether a program will ever print a particular message. Tools can check many specific cases or give warnings, but not a guaranteed answer for all programs.
This does not mean you can never tell whether a particular loop ends. For for ( int i ← 0; i < 10; i ← i + 1 ) you obviously can. The limit is on a single algorithm that works for every program.
Problems that are solvable but impractical
A problem is intractable when algorithms exist but all known ones need so much time or memory that realistic inputs are out of reach.
| n | 2ⁿ steps | n! steps | Time for n! at 10⁹ steps per second |
|---|---|---|---|
| 10 | 1,024 | 3,628,800 | about 0.004 seconds |
| 20 | about 1 million | about 2.4 × 10¹⁸ | about 77 years |
| 60 | about 1.15 × 10¹⁸ | about 8.3 × 10⁸¹ | far longer than the age of the universe |
Even the "better" exponential column fails quickly. At a billion steps per second, 2⁶⁰ steps take about 36.5 years. Faster hardware helps only a little. Doubling computer speed lets an O(2ⁿ) algorithm handle just one more item in the same time.
Well-known hard problems include finding the shortest route that visits every city once (the traveling salesperson problem), building the best school timetable, and packing items optimally into limited space. For these, no efficient exact algorithm is known.
Space limits
Memory can run out before time does. A table of distances between 1,000,000 locations would need 10¹² entries. At 4 bytes each, that is about 4 terabytes. Storing every possible chess position is impossible for the same reason. When a question describes a solution that stores every combination, or tries every possibility, check both time and space.
Factors that prevent a problem from being solvable
When a stem asks why a problem cannot be solved by a computer, sort the reason into one of these categories:
| Factor | Explanation | Example |
|---|---|---|
| Undecidable | No algorithm can exist | Deciding whether any given program halts |
| Intractable | An algorithm exists but needs too much time or memory at the required size | Checking every ordering of 60 delivery stops |
| Not well defined | The goal cannot be stated precisely enough for an algorithm | "Write the best possible song" |
| Missing or unavailable data | The needed inputs are not known or cannot be measured | Predicting a specific person's future choices |
| Resource constraints | Available hardware, storage, or time is too small for the input | Analyzing a video library too large for available storage |
Heuristics: good enough, fast enough
A heuristic is a problem-solving strategy that finds a reasonable answer quickly by using a rule of thumb, but gives no guarantee that the answer is optimal. Sometimes it gives no guarantee of any correct answer at all.
| Heuristic | How it works | Trade-off |
|---|---|---|
| Nearest neighbor for routing | Always drive to the closest unvisited stop next | Fast; routes are usually decent but seldom optimal |
| Greedy choice | Take the locally best option at each step | Can miss the global best |
| Game-playing evaluation | Score positions with a rule of thumb (material, mobility) instead of searching to the end of the game | Strong play, no guarantee of perfect play |
| Spam and malware filters | Flag messages or files with suspicious features | Occasional false positives and false negatives |
| Search ranking | Order results with estimated relevance signals | Useful results without a provably "best" order |
A greedy heuristic that fails
To make 6 cents from coins worth 1, 3, and 4 cents, a greedy rule ("always take the largest coin that fits") picks 4 + 1 + 1, which is three coins. The optimal answer is 3 + 3, two coins. With U.S. coin values the same greedy rule happens to be optimal, which shows that a heuristic's quality depends on the problem.
When is a heuristic the right choice?
- The exact solution is intractable for the input size, as with large routing and scheduling problems.
- A good-enough answer is acceptable. A delivery route 3% longer than the best one is fine if it can be found in seconds.
- Decisions are needed in real time, as with navigation apps, games, and robotics.
- The problem is poorly defined or the data are noisy, so exact optimality is not meaningful anyway.
A heuristic is a poor choice when a guaranteed correct or optimal answer is essential and an efficient exact algorithm exists, for example sorting grades or computing a bank balance.
A teacher wants a program that can examine any student's program, with any input, and always report correctly whether the student's program will eventually stop. Which statement is accurate?
A delivery company must plan routes each morning through about 200 stops, and a route that is a few percent longer than the best possible route is acceptable. Which approach is most appropriate?
An algorithm must examine 2⁶⁰ possibilities, and a computer checks one billion (10⁹) possibilities per second. Approximately how long will the computer take?