AQA 7517, section 4.4.4.5
Problems can be classified according to how hard they are to solve with an algorithm. The important dividing line is between polynomial time and anything worse.
Tractable problems
A problem is tractable if it has a solution that runs in polynomial time or better. That means the time complexity is for some fixed , or less, such as , , , , or .
Tractable problems can be solved in a reasonable time, even for large inputs. Examples:
- searching a list (linear or binary search);
- sorting (bubble sort , merge sort );
- finding the shortest path between two points (Dijkstra's algorithm).
Intractable problems
A problem is intractable if it has no polynomial time solution. The best known algorithms need exponential time () or worse (such as ).
An intractable problem can be solved in principle, because an algorithm exists, but for any but the smallest inputs the time needed is impractically long (see 4.4.4.4).
Examples:
- The travelling salesperson problem: find the shortest route that visits every one of cities exactly once and returns to the start. Checking every route takes about steps.
- Timetabling and scheduling with many constraints.
- Breaking some encryption by trying every key.
Comparing the two
| Tractable | Intractable | |
|---|---|---|
| Time complexity | Polynomial or better | Worse than polynomial (e.g. exponential) |
| Solved in reasonable time for large ? | Yes | No |
| Example | Sorting a list | Travelling salesperson, checking every route |
| Growth when doubles | A fixed multiple (e.g. 4 times for ) | Explodes |
The boundary matters because polynomial algorithms stay practical as inputs grow, while exponential ones don't.
Heuristic methods
Because intractable problems can't be solved exactly in a sensible time, heuristic methods are often used. A heuristic is a rule of thumb that finds a good solution quickly, though it is not guaranteed to be the best possible one.
For the travelling salesperson problem, a simple heuristic is the nearest neighbour method: from the current city, always go to the closest city not yet visited.
def nearest_neighbour(dist, start):
n = len(dist)
route = [start]
left = set(range(n)) - {start}
while left:
here = route[-1]
nxt = min(left, key=lambda c: dist[here][c])
route.append(nxt)
left.remove(nxt)
return route
This runs in time, which is fast, but the route it finds may be longer than the best one. For many practical uses, such as delivery planning, a good enough answer quickly is more useful than a perfect answer after years.
Worked example
Task: classify each as tractable or intractable, with a reason.
- Searching a sorted list of names (binary search), . Tractable: logarithmic is better than polynomial.
- Sorting items with merge sort, . Tractable: it is better than , which is polynomial.
- Trying every route to visit cities, . Intractable: worse than polynomial.
- Listing every subset of items, . Intractable: exponential, so it has no polynomial time solution.
Exam tip: give the definition in terms of polynomial time. Tractable means there is a solution in polynomial time or better, and intractable means there is none. Intractable problems are not impossible. They are just too slow, and heuristics are often used to get an acceptable answer.
Check yourself
What is a tractable problem?
A problem that has a polynomial (or better) time solution.
What is an intractable problem?
A problem that has no polynomial time solution, so it can't be solved in a reasonable time except for small inputs.
What is a heuristic and why is it used?
A rule of thumb that finds a good solution quickly, though not necessarily the best one. It is used on intractable problems, where finding the best answer would take too long.
Is an intractable problem the same as an unsolvable one?
No. An intractable problem can be solved by an algorithm, but it takes too long. An unsolvable (non-computable) problem has no algorithm at all.