Before you can read the parent note, you must own every piece of notation it throws at you. This page builds each one from absolute zero — plain words first, then the picture, then why the topic needs it. Read top to bottom; each block leans on the one above.
Look at the picture below. There are 4 dots (cities) joined by lines (roads). The red loop is one possible tour; there are many others. We want the cheapest loop among all of them.
The picture: n dots on paper. Naming them 0..n−1 instead of "Paris, Rome…" is not laziness — it means a city's name is an index we can plug straight into an array. That habit is what makes the code short.
Why the topic needs it
every loop and every array size below is written in terms of n.
Here is the trick that names the whole technique. We need to use a set of cities as an array index, and array indices must be plain integers. How do we squeeze a set into a single number?
Why the topic needs it
an integer is the cheapest possible array index, and there are exactly 2n of them for n cities — the second index of the DP table.
We picture a mask as a row of light switches, one per city. These four moves are all we ever need. Here &, |, ~ act on each bit position independently.
Now every symbol in the parent's central definition is earned:
That is the parent's mnemonic SET + SPOT — two indices, one for which cities, one for where you are. Branch and Bound attacks the same TSP differently (by pruning), but Held–Karp fills this table exhaustively and cleverly.
Cover the right side and answer aloud. If any stalls, reread its section.
What does naming cities 0..n−1 buy us?
A city's name is directly an array index, so cities plug straight into dist[i][j] and into bit i.
What does dist[i][j] hold, and what shape is it?
The cost to go from city i to city j; a 2-D grid (spreadsheet), mirrored across the diagonal if roads are two-way.
Why do we store the set of visited cities instead of the full path order?
Future cost depends only on which cities are ticked plus your current spot; order is already optimised inside the dp value, so keeping it would re-explode to n!.
Convert visited set {0,2} (with n=4) to a mask integer.