You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Many real-world problems require finding the best solution from a large set of possibilities — the shortest route, the minimum cost, the maximum profit. These are optimisation problems. When the search space is too large to explore exhaustively, we turn to heuristics — strategies that find good (but not necessarily optimal) solutions in a reasonable time.
An optimisation problem has:
For 20 cities: 20! = 2.4 × 10¹⁸ possible routes. Even a computer checking 1 billion routes per second would take 76 years to check them all.
| Classification | Definition | Example |
|---|---|---|
| Tractable | Can be solved in polynomial time — O(nᵏ) for some constant k | Sorting: O(n log n) |
| Intractable | Cannot be solved in polynomial time for all inputs; best known algorithms are exponential or factorial | TSP: O(n!) brute force |
| Computable | Can be solved by an algorithm (may take a very long time) | TSP (brute force does terminate) |
| Non-computable | Cannot be solved by any algorithm | The Halting Problem |
Exam Tip: Tractable does NOT mean "easy" — it means solvable in polynomial time. O(n¹⁰⁰) is technically tractable but impractical. In practice, we consider O(n²) or O(n³) as "reasonable".
| n | n² | 2ⁿ | n! |
|---|---|---|---|
| 10 | 100 | 1,024 | 3,628,800 |
| 20 | 400 | 1,048,576 | 2.4 × 10¹⁸ |
| 50 | 2,500 | 1.1 × 10¹⁵ | 3 × 10⁶⁴ |
| 100 | 10,000 | 1.3 × 10³⁰ | 9.3 × 10¹⁵⁷ |
For exponential and factorial problems, brute force becomes impossible even for moderate n. This is why we need heuristics.
A heuristic is a problem-solving strategy that produces a good enough solution in a reasonable time, without guaranteeing the optimal solution.
| Property | Detail |
|---|---|
| Not guaranteed optimal | The solution may not be the absolute best, but it is close |
| Much faster | Runs in polynomial time instead of exponential/factorial |
| Problem-specific | Different problems require different heuristics |
| Trade-off | Speed vs solution quality |
A greedy algorithm makes the locally optimal choice at each step, hoping to find a globally good solution.
Nearest Neighbour Heuristic for TSP:
This runs in O(n²) — much faster than O(n!) — but does not guarantee the shortest route.
Example:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.