Skip to main content

Proofs: Branch and Bound

Branch and bound finds the optimal solution only if its bounds and heuristics are valid. This page proves the facts used in the lessons: why the bounds of the examples are valid, why best-first branch and bound and A* stop at the optimum, and why the puzzle heuristics and the parity condition work. Safe pruning with a bound is proved in the backtracking chapter.


The bounds used in the examples are valid​

Task assignment. The bound of the B&B example is the cost so far plus, for each free task, the minimum cost in its column among the free agents.

Proof. In any complete assignment that extends the current one, each free task jj is done by some free agent ii, at cost C[i][j]≥min⁡free i′C[i′][j]C[i][j] \ge \min_{\text{free } i'} C[i'][j]. Adding over the free tasks, the remaining cost is at least the sum of the column minima. ■\blacksquare

The same argument works with the row minima (each free agent does some free task), and the maximum of two lower bounds is also a lower bound.

0/1 knapsack. The bound of the knapsack example is the value obtained by filling the remaining capacity greedily by value per weight, allowing a fraction of the last object.

Proof. Any way of completing the current selection with whole objects is, in particular, a valid solution of the fractional knapsack on the remaining objects and capacity. The greedy algorithm solves the fractional knapsack optimally, so its value is at least the value of any completion with whole objects. It is therefore an upper bound. ■\blacksquare


Best-first branch and bound stops at the optimum​

Claim. In the general scheme, with a valid lower bound in every node and the exact cost in every solution, when the loop stops (the heap is empty or its best estimate is at least UU), bestNode is an optimal solution (or there is none, if UU is still the initial limit and no solution was found).

Proof. At any moment, every unexplored solution lies in the subtree of some live node in the heap, or of a node that was pruned. Pruned nodes contain no solution cheaper than the value of UU at the moment they were pruned, which is at least the final UU (since UU only decreases). When the loop stops, every live node has estimate at least UU, because the heap returns its minimum, so their subtrees contain nothing cheaper than UU either. So no solution is cheaper than UU, and bestNode has cost UU. ■\blacksquare

The order of the heap affects how fast the bound UU improves, and therefore how much is pruned, but not the correctness.


A* with an admissible heuristic finds an optimal path​

Consider a search where each node xx has g(x)g(x), the cost of the path from the start to xx, and h(x)h(x), an estimate of the cost from xx to the goal. The live nodes are ordered by f(x)=g(x)+h(x)f(x) = g(x) + h(x).

Claim. If hh is admissible (h(x)≤h∗(x)h(x) \le h^*(x), the true remaining cost, for every xx, and in particular h=0h = 0 at the goal), the first goal node extracted from the priority queue has minimum cost.

Proof. Let C∗C^* be the cost of an optimal solution, and suppose that a goal node tt with cost g(t)>C∗g(t) \gt C^* is extracted first. At that moment, some node xx on an optimal path is still live (the start node is on it, and each time a node of the path is expanded, its successor on the path enters the queue). For that node, g(x)g(x) is its cost along the optimal path, so

f(x)=g(x)+h(x)≤g(x)+h∗(x)=C∗<g(t)=f(t)f(x) = g(x) + h(x) \le g(x) + h^*(x) = C^* \lt g(t) = f(t)

The queue would have extracted xx before tt: a contradiction. ■\blacksquare

The proof assumes that a node reached later by a cheaper path is updated or reinserted (as in the 8-puzzle measurements of the lessons). Ordering by hh alone breaks the inequality, because gg is missing, which is why the "greedy" version found much longer solutions in the measurements.


The puzzle heuristics are admissible​

Misplaced tiles. Each tile that is not in its final cell must move at least once, and each move moves one tile. So the number of moves is at least the number of misplaced tiles. ■\blacksquare

Manhattan distance. Each move slides one tile to an adjacent cell, which changes that tile's Manhattan distance by exactly 1 and leaves the others unchanged. So the total distance decreases by at most 1 per move, and reaching total distance 0 needs at least as many moves as the initial distance. ■\blacksquare

Both arguments count only the numbered tiles. If the empty cell is counted, the first argument fails: a board solved in one move can have two "misplaced" pieces (the tile and the gap).


The parity condition of the 15-puzzle​

The reachability test says that the goal can be reached if and only if ∑smaller(i)+x\sum \text{smaller}(i) + x is even. We prove that the condition is necessary: if the sum is odd, no sequence of moves reaches the goal.

Proof. Read the board row by row, with the empty cell as tile 16. Then ∑smaller(i)\sum \text{smaller}(i) is the number of inversions of that sequence, and xx indicates the color of the empty cell on a checkerboard. Every move swaps the empty cell with a neighbor:

  • A horizontal move swaps two adjacent elements of the sequence: the number of inversions changes by exactly 1.
  • A vertical move swaps the empty cell with the tile 4 positions before or after it in the sequence, with 3 tiles in between. The moving tile passes over those 3 tiles (3 pairs change order), the empty cell passes over the same 3 tiles in the other direction (3 more pairs), and the pair formed by the moving tile and the empty cell also changes order. In total, 7 pairs change order: an odd number.

So every move changes the parity of the number of inversions. Every move also changes the color of the empty cell's square (xx flips between 0 and 1). The parity of the sum therefore never changes. The goal has 0 inversions and the empty cell on an unshaded square, so its sum is 0, even. A board with an odd sum can never reach it. ■\blacksquare

The converse (every board with an even sum can reach the goal) is also true, but its proof is constructive and longer: it shows how to move any tile to its place without disturbing the ones already placed. It was published by Johnson and Story in 1879.

Saved only in your browser
Was this lesson helpful?
Questions, or something wrong?

Errors, suggestions and public questions open a form on GitHub, visible to everyone.