Hard & Impossible Problems

AdvancedAbout 12 minProgramming & algorithms

Some problems take a computer a second. Some would take longer than the age of the universe. And a few can't be solved at all.

Reasonable and Unreasonable Time

Computer scientists judge an algorithm by how its number of steps grows as the input gets bigger. Double the size of a list, and:

  • finding the largest item takes about twice as many steps (it grows like n),
  • a simple sort might take about four times as many (it grows like n²).

Growth like n, n² or n³ is called reasonable time. But some problems grow far faster — like 2ⁿ, or n! ("n factorial", which is n × (n − 1) × … × 1). That's unreasonable time: fine for tiny inputs, hopeless for big ones, no matter how fast the computer.

The Delivery Driver's Problem

A driver has to visit several stops and come back. What's the shortest route? The only sure way to know is to try every possible order — and the number of orders explodes as stops are added.

Try it yourself

—Shortcut length
—Best length

6

Good Enough: Heuristics

When the exact answer would take too long, programs use a heuristic: a shortcut that finds a good answer quickly, even if it's not always the best. "Always drive to the nearest stop next" is one. Map apps, delivery companies and airline schedules all rely on heuristics every day.

A heuristic trades a guarantee of the best answer for an answer you can actually get in time.

Problems No Program Can Solve

Some problems aren't just slow — they're undecidable. That means it has been proven that no algorithm can give the right yes-or-no answer for every possible input.

The most famous is the halting problem: "Will this program eventually stop, or run forever?" For a specific program you can often tell. But in 1936, Alan Turing proved that no single program can answer that question correctly for every program. It isn't that nobody has found the trick yet — there is no trick to find.

So there are three kinds of problem: ones computers solve quickly, ones they can only solve quickly with a good-enough heuristic, and ones no computer will ever fully solve.

Check your understanding

5 quick questions. Pick one answer for each — you'll see why straight away.

  1. An algorithm's steps grow like n² as the input size n grows. Is that reasonable time?

  2. A delivery app can't check every possible route, so it always goes to the nearest stop next. That approach is called…

  3. Adding one more stop to a delivery route multiplies the number of possible routes. What kind of growth is that?

  4. What does it mean for a problem to be undecidable?

  5. Which is a famous example of an undecidable problem?