AP® Computer Science Principles · Big Idea 3 · Topic 3.17

Reasonable and Unreasonable Running Time

An algorithm runs in reasonable time if its steps grow polynomially with input size, and unreasonable time if they grow exponentially, doubling or worse with every added item until no computer can keep up.

Running time is about how the number of steps grows as the input gets bigger, not how many seconds a specific run takes. Polynomial growth, like n or n squared or n cubed, climbs steadily. Double the input and the work grows by some fixed multiple. Exponential growth, like 2 to the n, climbs by repeatedly multiplying itself. Each single extra item doesn't add a fixed chunk of work, it doubles everything that came before. That's why small inputs look fine and then, a few items later, the algorithm is suddenly asking for more steps than exist seconds in the universe.

The mechanism is in the shape of the function. A polynomial like n squared grows because you're doing roughly n units of work for each of n items, a controlled multiplication. An exponential like 2 to the n grows because each new item doubles the entire previous total, an uncontrolled multiplication that compounds on itself. At n equal to 10, n squared is 100 and 2 to the n is 1024, already ten times bigger. At n equal to 30, n squared is 900, but 2 to the n is over a billion. The gap isn't a head start, it's a different kind of growth entirely.

This idea sits right where algorithms meet the limits of computation. Reasonable time, polynomial or better, means bigger computers or smarter code can realistically keep pace with bigger problems. Unreasonable time, exponential, means the problem is still solvable in principle, but no amount of ordinary hardware improvement rescues it for real-sized inputs. That distinction is the bridge into thinking about problems that are solvable fast, solvable only slowly, and problems with no algorithm at all.

Key terms

Reasonable time
Running time that grows polynomially with input size, so larger inputs stay practically solvable.
Unreasonable time
Running time that grows exponentially with input size, becoming impractical for even modestly larger inputs.
Polynomial growth
Growth like n, n squared, or n cubed, where work scales by a fixed power of the input size.
Exponential growth
Growth like 2 to the n, where each added item multiplies the total work instead of adding a fixed amount.

Watch it explained

  1. How it worksHow does polynomial growth stay manageable while exponential growth explodes?
  2. Worked exampleShow me n squared and 2 to the n plotted together as n runs from 1 up to 30.
  3. Worked exampleFind how long a 2 to the n algorithm takes at n of 60 on a machine doing a billion steps a second.
  4. Common mistakeWhy isn't a faster computer the fix for an algorithm that runs in unreasonable time?

Check yourself

Your turn1 of 2
Find how long a 2n algorithm takes at n of 34 on a machine doing 649345006 steps a second, in seconds.

End of topic.