Quiz 2

Exact Algorithms — Branch & Bound, DP for TSP, Local Search

538 words
3 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Exact Algorithms — Branch & Bound, DP for TSP, Local Search ## 🎯 Learning Objectives - Apply branch and bound to combinatorial optimization - Implement Held-Karp DP for TSP in O(n²2ⁿ) time - Design local search algorithms with neighborhood structures - Understand when exact algorithms are feasible * * * ## 1. Bra...

Exact Algorithms — Branch & Bound, DP for TSP, Local Search

🎯 Learning Objectives

  • Apply branch and bound to combinatorial optimization
  • Implement Held-Karp DP for TSP in O(n²2ⁿ) time
  • Design local search algorithms with neighborhood structures
  • Understand when exact algorithms are feasible

1. Branch and Bound

1.1 Framework

(Diagram)

1.2 TSP via Branch and Bound

  • Branch: Choose an edge to include or exclude
  • Bound: Compute MST of remaining graph (lower bound = MST cost + current path cost)
  • Prune: If bound ≥ best tour found, discard

2. Held-Karp DP for TSP

2.1 Recurrence

DP[S][i]=minjS{i}{DP[S{i}][j]+dist(j,i)}DP[S][i] = \min_{j \in S \setminus \{i\}} \{DP[S \setminus \{i\}][j] + dist(j, i)\}
Where SS is set of visited cities (including 1), ii is ending city. Base: DP[{1}][1]=0DP[\{1\}][1] = 0 Answer: mini1DP[{1..n}][i]+dist(i,1)\min_{i \neq 1} DP[\{1..n\}][i] + dist(i, 1)

2.2 Tracing: 4 cities

| Distance matrix: | | [0,10,15,20][0, 10, 15, 20] | | [10,0,35,25][10, 0, 35, 25] | | [15,35,0,30][15, 35, 0, 30] | | [20,25,30,0][20, 25, 30, 0] |
SiDP[S][i]Previous
{1,2}2101
{1,3}3151
{1,4}4201
{1,2,3}215+35=503
{1,2,3}310+35=452
{1,2,4}220+25=454
{1,2,4}410+25=352
{1,3,4}320+30=504
{1,3,4}415+30=453
{1,2,3,4}245+25=704
{1,2,3,4}335+30=654
{1,2,3,4}445+25=702
Minimum = min(DP[{1,2,3,4},2]+d(2,1), DP[{1,2,3,4},3]+d(3,1), DP[{1,2,3,4},4]+d(4,1)) = min(70+10, 65+15, 70+20) = min(80, 80, 90) = 80 Optimal tour: 1→3→4→2→1 = 15+30+25+10 = 80

3.1 Framework

  1. Start with feasible solution
  2. Find improving neighbor (defined by neighborhood structure)
  3. If found, move to neighbor; repeat
  4. If no improving neighbor → local optimum

3.2 TSP: 2-opt Neighborhood

Remove two edges, reconnect in other way. Example: Tour 1→2→3→4→1. If edges (1,2) and (3,4) cross, swap to 1→3→2→4→1.

4. Common Pitfalls

Pitfall 1: Bound Too Weak

The mistake: Using a bound that doesn't prune enough. Correct approach: MST bound for TSP is effective. LP relaxation is stronger but slower.

Pitfall 2: Local Search Getting Stuck

The mistake: Accepting local optimum as final answer. Correct approach: Use simulated annealing (accept worsening moves with decreasing probability) or restart from different start points.

5. Key Concepts Reference

MethodTimeSpaceGuarantee
Branch & BoundExponentialPolynomialOptimal
Held-Karp DPO(n²2ⁿ)O(n2ⁿ)Optimal
2-opt Local SearchO(n³) per iterationO(n)Local optimum
Simulated AnnealingDependsO(n)Probabilistic

6. 📝 Practice Questions

Q1: Held-Karp DP for 6 cities needs how many subsets?
Answer: Sum of C(5, k) for k=1..5 = 2^5 = 32 subsets (excluding empty set, always including city 1). For each subset, up to n-1 ending cities. Total states: O(n × 2^{n-1}) ≈ O(n2^n). Q2: Why does Held-Karp take O(n²2ⁿ) and not O(n2ⁿ)?
Answer: For each DP[S][i] (n × 2^n states), we minimize over j ∈ S{i}. In the worst case, |S| ≈ n, giving O(n) per state. Total = O(n² × 2^n). Q3: When would you use local search over branch and bound?
Answer: Local search: when approximate solution is acceptable, problem instance is large, and good solutions are quickly found. B&B: when optimality is required and instance is small enough (n ≤ 20 for TSP).

7. 🔗 Cross-References

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.