Explore Library
Code QuizAdvanced

Branch and Bound Inverted Prune

This minimizer prunes exactly the branches it should keep — find the bug.

Codejavascript
// Minimization search: `best` = cheapest complete solution found so far
function search(node, best) {
  if (isLeaf(node)) return Math.min(best, cost(node));
  const bound = lowerBound(node); // optimistic estimate
  if (bound <= best) return best; // prune this branch
  for (const child of expand(node)) {
    best = search(child, best);
  }
  return best;
}

The optimal solution is often pruned away. What is the bug?