3.7.18 · D1Algorithm Paradigms

Foundations — Branch and bound

3,253 words15 min readBack to topic

This page assumes you know nothing. Before you can read the parent note, you need a small toolbox of pictures and symbols. We build each one from zero, in an order where every piece rests on the piece before it.


0. What is an "optimization problem"?

Picture a shelf of finished answers, each with a price tag. An optimization problem is not "find an answer" — it is "find the answer with the smallest (or largest) tag."

  • Minimization = smallest tag wins (cheapest tour).
  • Maximization = largest tag wins (most-valuable knapsack).

The topic needs this because B&B only makes sense when there is a "best" to chase. If you just want any legal answer, you'd use plain Backtracking instead.

Figure — Branch and bound

Every dot on that shelf is a complete answer; the red dot is the optimum. B&B's whole job is to find the red dot without inspecting most of the black dots.


1. The objective function and its symbols

  • ::: stands for one complete candidate answer (a full tour, a full item-selection).
  • ::: the single number we compare answers by.

Why the topic needs it: pruning is one comparison of numbers. Without a number per answer, there is nothing to compare.


2. What is a "solution tree"? (branching)

Figure — Branch and bound

Read the figure top-to-bottom:

  • The root (top) is an empty choice.
  • Each node branches into children — one child per option of the next decision (here: include item vs exclude item).
  • A partial node in the middle = "some decisions made, some still open."
  • A leaf = a full answer, ready to price.

"Branch" in "Branch and Bound" is literally this: splitting one node into its children.


3. The symbols , , — comparing and constraining

Figure — Branch and bound

Look at the figure: the sign is like a mouth that always opens toward the bigger number and its point aims at the smaller one. In the wide open side faces , so is the larger side; in the open side faces . That single picture tells you which side wins — no memorizing needed.

In the parent note you meet . This is a constraint: a rule an answer must obey to be legal (feasible). is just a fixed number — the knapsack's capacity.

  • ::: the fixed limit (max weight the bag holds).
  • ::: the weight already used by decisions made so far.
  • ::: the capacity still remaining.

Picture a bag with a fill-line at . As you drop items in, rises toward the line; is the gap left below it. When the answer is illegal — it overflows.


4. The incumbent — best-so-far

Picture a scoreboard with one line: "Best so far: ₹100." Every time we finish a leaf that beats it, we overwrite that line.

Why the topic needs it: the incumbent is the yardstick. Pruning asks "can this branch beat the champion?" — with no champion, nothing to compare against, so we start it at (minimization) or (maximization), meaning "no champion yet, everything beats nothing."

  • ::: "infinity," a value larger than any real number — a placeholder meaning "unbeaten."

5. The bound — the optimistic guess (the heart)

Figure — Branch and bound

In the figure, the red horizontal line is the node's bound. Every leaf under that node lives on the worse side of the red line — that is what "guaranteed" means.

How do we get such a guaranteed guess? By relaxation:

Let us now build, from these symbols, the exact upper bound the parent note uses for 0-1 Knapsack. First we name the item symbols:

  • ::: profit (value) already collected by decisions made at this node.
  • ::: value of item ; ::: weight of item .
  • ::: value-density, "rupees per kilo" — how good an item is per unit weight.

Deriving the fractional-knapsack bound step by step

0-1 Knapsack forbids fractions of items (each item is 0 or 1). Relax that rule — allow fractions. Because fractions give more freedom, the relaxed maximum is the true maximum, so it is a valid upper bound. Here is how greedy computes it at one node.

Walk the bag-filling, tracking the space left. We already have profit and used weight , so the space to fill is (our remaining capacity from Section 3).

Step 1 — pour in whole items that fit. Go through the not-yet-decided items in density order. Each one that entirely fits into the space left, drop it in fully: it adds its full value . As we do this the free space shrinks. Call the space still free at the moment we can no longer fit a whole item — it is simply "how much of is left after the whole items went in." So is the same kind of number as , just measured a few items later; it is not new notation, only a later snapshot of the remaining space.

  • ::: any item that goes in fully (fits whole into the space left).
  • ::: the space still free after all the whole items are packed. Starts at , only shrinks.

Step 2 — meet the first item that does NOT fit; call it . Item is simply the first item in density order whose full weight is bigger than the free space . It is not chosen by magic — it is whichever item the pouring process bumps into first that would overflow the bag.

  • ::: the first density-ordered item that overflows — it fits only partly.

Step 3 — shave off exactly the fraction of that fits (when exists). We have space and item weighs . So the fraction of that fits is (space available ÷ item's weight). Why divide these two? If the item weighs and we only have room for , the portion we can take is "room over full weight." That fraction of carries that same fraction of 's value: If (bag already exactly full), the fraction is and no piece is added — the formula still works.

Putting the three steps together gives the node's upper bound:


6. The pruning rule — one comparison

Figure — Branch and bound

The figure shows two nodes. The kept node's bound sits on the winning side of the incumbent line (it might beat the champion). The red pruned node's bound sits on the losing side — deleted, along with everything below it, in one comparison.


7. The live set and picking order

We pull… Container Name
oldest queue (FIFO) BFS B&B
newest stack (LIFO) DFS B&B
best bound priority queue Least-Cost B&B
  • Queue ::: a line at a shop — first in, first out.
  • Stack ::: a pile of plates — last on, first off.
  • Priority queue ::: a magic bag that always hands you the most promising node first.
Figure — Branch and bound

Why the topic needs it: pulling the best-bound node first tends to find a strong incumbent early, which makes the prune test fire more often — less total work.


8. Growth notation ,

Why the topic needs it: B&B does not change the worst-case growth — if nothing prunes, the tree is still fully or . It only speeds up the typical case. This is a common trap addressed in the parent's mistakes.


How these foundations feed the topic

The pieces you just built stack up in one clean chain. Read the map below one arrow at a time, top to bottom:

  1. An optimization problem gives you the very notion of a "best" answer.
  2. That best is measured by an objective value, — the number we compare.
  3. Candidate answers get organised into a solution tree by branching; at any moment a partial node carries a remaining capacity .
  4. Separately, the best complete answer found so far is the incumbent.
  5. At each partial node, relaxation produces a bound — the optimistic guess.
  6. The prune test compares that bound against the incumbent; combined with the live set ordering, this is Branch and Bound.

Optimization problem

Objective value cost of x

Solution tree branching

Partial node with capacity c

Incumbent best so far

Relaxation gives a bound

Bound optimistic guess

Prune test bound vs incumbent

Branch and Bound

Related paradigms that share pieces of this toolbox: Backtracking (branching + feasibility, no bound), Dynamic Programming (also finds optima, different mechanism), and applications Travelling Salesman Problem and A* Search (which is B&B with a heuristic bound).


Equipment checklist

Cover the answer and test yourself before reading the parent note.

What does an optimization problem ask for, versus a plain search?
The single best answer by a number (objective), not just any legal answer.
What is ?
The one number that prices a complete answer , used to compare answers.
In the solution tree, what is a leaf versus a partial node?
A leaf = a complete answer ready to price; a partial node = some decisions made, some open.
What do , , and mean?
= weight used, = capacity limit, = remaining capacity.
What is the incumbent, and why start it at (min)?
Best complete answer so far; means "no champion yet, anything beats it."
Why must a bound be optimistic, not pessimistic?
A pessimistic guess could prune a branch hiding the true optimum; an optimistic (over/under) estimate proves safety.
How do we obtain a valid bound?
Relax (delete a rule), solve the easier problem — its optimum is a guaranteed over/under estimate.
Why is highest-density-first optimal for the fractional fill?
Exchange argument — swapping any lower-density kilo for a higher-density kilo raises value at the same weight, so density order can't be beaten.
In the knapsack bound, what are , , and ?
= space still free when whole items stop fitting; = an item packed fully; = the first item that overflows and is taken as a fraction.
What happens to the bound when NO item overflows?
There is no and no fraction term; the bound is just plus every remaining item's full value.
Why is the shaved value ?
The fraction of that fits is room ÷ full weight , and it carries that same fraction of 's value.
State the prune test for minimization and maximization.
Min: prune if bound incumbent. Max: prune if bound incumbent.
When is pruning an equal-bound (tie) branch unsafe?
When you want all optimal solutions — a tied branch may hold a different answer of equal optimal value; use strict / then.
What does a priority-queue live set give us?
Least-Cost B&B — always expand the most promising (best-bound) node first.
Does B&B beat brute force in the worst case?
No — worst case is still /; B&B only helps the typical case via pruning.