You have a knapsack that holds 10 kilograms and a pile of items, each with a weight and a value. Which subset fits and is worth the most? This is the knapsack problem, and it is NP-hard: nobody knows a method that stays fast as the item count grows, and the only sure way is, in the worst case, to consider every subset — of them.
And yet solvers crack knapsacks with hundreds of items in the blink of an eye. Airlines, factories and delivery networks solve far nastier versions every day. How, if the problem is intractable?
The trick is branch and bound. You still organize the search as a giant tree of choices — take this item, or leave it — but you never walk the whole tree. At each branch you compute a quick bound: the best you could possibly achieve down that path. If that optimistic best can't beat a solution you already have, you prune the entire subtree, unexplored. Worst case it is still exponential. In practice, it makes the impossible routine.
Comments
Loading comments...