AI Search · Exam notes

TSP Branch and Bound: Complete Walkthrough

Every paper carries one TSP Branch and Bound comprehension with four sub-questions. The tree is given, the algorithm is frozen, and every answer is read off the tree. The four questions are always: which nodes are refined next? which node is the optimal tour and its cost? how many cities? what is the tour from A? All five trees on this page are real trees from past papers, with official answers. These notes teach exactly that skill, nothing more.

How to use this page: read points 1 to 3 once. Then work the 2024T2 tree in point 4 from its table, and check yourself against the animation. Then solve the four practice trees in point 6 with a pen before opening the answers.

1. TSP setup: cities, matrix, tour

TSP: visit every city exactly once and return to the start, minimising total cost. Input is a cost matrix. A tour on \(n\) cities uses exactly \(n\) edges.

Example cost matrix (symmetric)

ABCD
A-101520
B10-3525
C1535-30
D202530-

Solved mini-example. Tour A,B,D,C,A costs 10 (AB) + 25 (BD) + 30 (DC) + 15 (CA) = 80. Tour A,C,B,D,A costs 15 + 35 + 25 + 20 = 95. So the first is better. Every TSP question below is this same comparison, scaled up and organised by the search tree.

2. Branch and Bound for TSP: the refinement space

The search space here is not a map. It is a refinement space: the root node S0 is the set of all possible tours. Refining a node means splitting its tour set in two using one edge: one child includes the edge (label XY), the other excludes it (label ¬XY; the question text writes it as ~XY).

Each node carries a cost = lower bound on the best tour inside its set. A lower bound never overestimates: every tour in that set costs at least the bound. The algorithm is one line:

Always refine the unrefined leaf with the smallest cost. Stop when that leaf is a fully refined single tour. At that point no other leaf can beat it, because every other leaf only promises a bound at or above its actual cost.

Solved mini-example. Leaves: b1 (cost 218), b2 (cost 235). Refine b1: it promises the cheaper set. Its children c1 (250), c2 (222) join the leaves. Now leaves are b2 (235), c1 (250), c2 (222). Refine c2. That is the whole algorithm, repeated.

3. How to read the search tree

Every node in the exam tree shows three things:

  1. Edge: XY means every tour in this set uses edge XY; ¬XY means no tour in this set uses it. The root S0 has no edge.
  2. Cost: the lower bound for this set. Costs never decrease along a refinement path in a correct tree.
  3. Reference number: a unique id like a1, b1, b2, c1. The letter is the depth level, the digit counts nodes at that level. Ties in cost are broken by reference number (compare alphabetically: b1 before b2, any b before any c).

Solved mini-example. Node "b1, AD, 224" reads: first-level node, every tour here includes edge AD, cheapest such tour costs at least 224. If another leaf also shows 224, say b2, refine b1 first (b1 comes first alphabetically).

4. Worked example: 2024T2 FN, Q57 to Q60 (real tree)

4a. The tree as a table (solve from this, then check the animation)

RefEdgeCostChildren
a1S0 (all tours)224b1 (AD), b2 (¬AD)
b1AD224c1 (BD), c2 (¬BD)
b2¬AD244c3 (BD), c4 (¬BD)
c1BD276-
c2¬BD242d1 (BC), d2 (¬BC)
c3BD244d3 (BC, tour), d4 (¬BC)
c4¬BD270-
d1BC242e1 (AC), e2 (¬AC)
d2¬BC340-
d3BC, tour A-C-B-D-E-A244-
d4¬BC255-
e1AC268-
e2¬AC, tour A-D-C-B-E-A249-

Cover the animation below. Starting from a1, list each refinement by picking the cheapest unrefined leaf, then find the cheapest complete tour. Official answers: b1,c2,d1,b2; d3,244; 5; A,C,B,D,E.

4b. Animation: the full tree, highlighted step by step

The animation below hides nothing: every node is visible from the start. Stepping forward only marks progress. Black means refined, outline means refining right now, grey means the two new leaves that refinement has just produced, thick border at the end means the optimal tour. The ¬ sign marks exclusion (the question text writes ~AD): ¬AD means the edge AD is excluded.

Step 0

Why this refinement

Unrefined leaves at this step

4c. Full question

The TSP Branch and Bound algorithm is solving a TSP instance with cities A, B, C, and so on. The search tree at the time the algorithm has discovered the optimal tour is shown below. Each node displays an edge (either XY or ¬XY), a cost value, and a unique reference number (a1, b1, b2, c1, c2, c3, c4, d1, d2, d3, d4, e1, e2). Use the reference numbers to break ties.

  1. Let S0 (ref. no. a1) be the first node refined. Identify the next 4 nodes (2nd to 5th) refined, in order (format a9,b9,c9,d9).
  2. Which node represents the optimal tour, and what is its cost (format a9,42)?
  3. Determine the number of cities (integer, or NIL).
  4. Starting from city A, what is the path representation of the optimal tour (format A,X,Y)?

4d. Step by step solution

  1. Refinement order. 1st: a1 (only node). It generates b1 (AD, 224) and b2 (¬AD, 244). Min is b1, so 2nd: b1. It generates c1 (BD, 276) and c2 (¬BD, 242). Leaves: c2 (242), b2 (244), c1 (276). Min is c2, so 3rd: c2. It generates d1 (BC, 242) and d2 (¬BC, 340). Leaves: d1 (242), b2 (244), c1 (276), d2 (340). Min is d1, so 4th: d1. It generates e1 (AC, 268) and e2 (¬AC, 249). Leaves: b2 (244), e2 (249), e1 (268), c1 (276), d2 (340). Min unrefined leaf is b2 (244), so 5th: b2. It generates c3 (BD, 244) and c4 (¬BD, 270). Leaves: c3 (244), e2 (249). Min is c3, so 6th: c3. It generates d3 (BC, 244, complete tour) and d4 (¬BC, 255). Answer to Q57: b1,c2,d1,b2.
  2. Optimal node. Scan all leaves for a fully refined single tour with the smallest cost: d3 is the complete tour A-C-B-D-E-A costing 244. The only other complete tour is e2 (249). Every partial leaf promises a bound at or above 244 (c1: 276, d2: 340, c4: 270, d4: 255). So none can beat d3. Answer to Q58: d3,244.
  3. Number of cities. The optimal tour A-C-B-D-E-A uses edges AC, CB, BD, DE, EA. Distinct cities: A, B, C, D, E. Answer to Q59: 5. Rule: count distinct city letters; a tour on n cities has exactly n edges.
  4. Tour from A. Walk the tour edges from A: A to C (AC), C to B (CB), B to D (BD), D to E (DE), E to A (EA). Answer to Q60: A,C,B,D,E. The reverse walk A,E,D,B,C is the same tour and is accepted. Note the path is consistent with the tree: the d3 branch includes BC and BD (via c3) and excludes AD (via b2).

5. Practice: four more real trees

Each tree below is a real past paper tree. For each one, answer all four sub-questions with a pen, then open the answer. Rule throughout: refine the min-cost unrefined leaf, ties by reference number.

Tree P1: 2024T3 FN, Q62 to Q65 (small, asks 2nd to 4th)

RefEdgeCostChildren
a1S0196b1 (BC), b2 (¬BC)
b1BC196c1 (BD), c2 (¬BD)
b2¬BC230c3 (BD), c4 (¬BD)
c1BD232-
c2¬BD236-
c3BD230d1 (AD, tour), d2 (¬AD)
c4¬BD310-
d1AD, tour A-C-E-B-D-A230-
d2¬AD271-

Q: 2nd to 4th refined? Optimal node and cost? Cities? Tour from A?

Step 0

Why this refinement

Unrefined leaves at this step

Answer P1

b1,b2,c3; d1,230; 5; A,C,E,B,D. Trace: a1 first. Leaves b1 (196), b2 (230): 2nd is b1. It makes c1 (232), c2 (236). Leaves b2 (230), c1 (232), c2 (236): 3rd is b2. It makes c3 (230), c4 (310). Leaves c3 (230), c1 (232): 4th is c3. It makes d1 (230, tour) and d2 (271). Cheapest fully refined leaf is d1 (230). Path a1, b2 (¬BC), c3 (BD), d1 (AD) forces AC, CE, EB: tour A,C,E,B,D. Reverse A,D,B,E,C also accepted.

Tree P2: 2024T3 AN, Q62 to Q65 (small, asks 2nd to 4th)

RefEdgeCostChildren
a1S0131b1 (BC), b2 (¬BC)
b1BC131c1 (AC), c2 (¬AC)
b2¬BC167-
c1AC176-
c2¬AC162d1 (BD, tour), d2 (¬BD)
d1BD, tour A-D-B-C-E-A162-
d2¬BD198-

Q: 2nd to 4th refined? Optimal node and cost? Cities? Tour from A?

Step 0

Why this refinement

Unrefined leaves at this step

Answer P2

b1,c2,d1; d1,162; 5; A,D,B,C,E. Trace: a1 first. Leaves b1 (131), b2 (167): 2nd is b1. It makes c1 (176), c2 (162). Leaves c2 (162), b2 (167), c1 (176): 3rd is c2. It makes d1 (162, tour) and d2 (198). Leaves d1 (162, tour), b2 (167): 4th is d1, which is already the complete tour, so it is optimal on the spot. Path a1, b1 (BC), c2 (¬AC), d1 (BD) forces AD, CE, EA: tour A,D,B,C,E. Reverse A,E,C,B,D also accepted.

Tree P3: 2024T1 FN, Q100 to Q103 (big, 6 cities)

RefEdgeCostChildren
a1S0380b1 (DE), b2 (¬DE)
b1DE380c1 (BC), c2 (¬BC)
b2¬DE422-
c1BC380d1 (BE), d2 (¬BE)
c2¬BC406-
d1BE395e1 (AD), e2 (¬AD, tour)
d2¬BE398e3 (BD), e4 (¬BD)
e1AD454-
e2¬AD, tour A-C-B-E-D-F-A402-
e3BD434-
e4¬BD428-

Q: 2nd to 5th refined? Optimal node and cost? Cities? Tour from A?

Step 0

Why this refinement

Unrefined leaves at this step

Answer P3

b1,c1,d1,d2; e2,402; 6; A,C,B,E,D,F. Trace: a1 first. Leaves b1 (380), b2 (422): 2nd is b1. It makes c1 (380), c2 (406). Leaves c1 (380), c2 (406), b2 (422): 3rd is c1. It makes d1 (395), d2 (398). Leaves d1 (395), d2 (398): 4th is d1. It makes e1 (454), e2 (402, tour). Leaves d2 (398), e2 (402), c2 (406): 5th is d2. It makes e3 (434), e4 (428). Fully refined leaves: e2 (402), e4 (428), e3 (434), e1 (454). Cheapest is e2 (402). Path a1, b1 (DE), c1 (BC), d1 (BE), e2 (¬AD) forces AC, CB, DF, FA: tour A,C,B,E,D,F. Six distinct cities. Reverse A,F,D,E,B,C also accepted.

Tree P4: 2025T2 FN, Q69 to Q73 (big, optimal found late)

RefEdgeCostChildren
a1S0375b1 (BD), b2 (¬BD)
b1BD375c1 (CD), c2 (¬CD)
b2¬BD414c3 (CD), c4 (¬CD)
c1CD418d1 (AB), d2 (¬AB)
c2¬CD410d3 (AB, tour), d4 (¬AB)
c3CD414d5 (AB), d6 (¬AB)
c4¬CD452-
d1AB456-
d2¬AB548-
d3AB, tour A-B-D-E-C-A434-
d4¬AB468-
d5AB414e1 (AD), e2 (¬AD)
d6¬AB572-
e1AD436-
e2¬AD472-

Q: 2nd to 5th refined? Optimal node? Optimal cost? Cities? Tour from A?

Step 0

Why this refinement

Unrefined leaves at this step

Answer P4

b1,c2,b2,c3; d3; 434; 5; A,B,D,E,C. Trace: a1 first. Leaves b1 (375), b2 (414): 2nd is b1. It makes c1 (418), c2 (410). Leaves c2 (410), b2 (414), c1 (418): 3rd is c2. It makes d3 (434, tour), d4 (468). Leaves b2 (414), c1 (418): 4th is b2. It makes c3 (414), c4 (452). Leaves c3 (414), c1 (418): 5th is c3. It makes d5 (414), d6 (572). Then d5 (414) is refined into e1 (436), e2 (472). Fully refined leaves: d3 (434), e1 (436), d4 (468), e2 (472), d6 (572). Cheapest is d3 (434). Path a1, b1 (BD), c2 (¬CD), d3 (AB) forces DE, EC, CA: tour A,B,D,E,C. This paper asked node and cost separately (Q70: d3, Q71: 434).

6. Exam checklist (write this on the rough sheet)

  1. Refinement order: a1 first, then always the min-cost unrefined leaf; ties by reference number (b1 before b2, any b before any c).
  2. After each refinement, list all current unrefined leaves with costs before picking the next. Never pick from memory.
  3. Optimal = cheapest fully refined leaf (a complete tour), answer as ref,cost. Partial leaves with higher bounds are pruned by definition.
  4. Cities = distinct city letters in the optimal tour. A tour on n cities has exactly n edges.
  5. Tour from A: walk the tour edges from A; reverse is accepted. No spaces in the answer. NIL only if no complete tour exists.