Exercises
Thirteen problems covering the whole course: ratios and lower bounds, combinatorial algorithms, LP rounding and primal-dual, approximation schemes and hardness. Each has a short Answer and a full Solution; several solutions include a program that checks the result by brute force. Work each one on paper first.
Tip: For any claimed ratio, name the lower bound (for minimization) or upper bound (for maximization) it is measured against, and find an instance where the algorithm meets it. For any hardness claim, name the gap and the assumption.
| # | Exercise | Practises |
|---|---|---|
| 1 | What a dual certifies | lower bounds, weak duality |
| 2 | Matchings on a path | vertex cover, best and worst case |
| 3 | Greedy set cover by hand | greedy, the bound |
| 4 | Christofides on a square | MST, odd vertices, matching |
| 5 | Farthest-first on a line | -center |
| 6 | LPT on two machines | makespan, tightness |
| 7 | Rounding the 5-cycle | half-integrality, LP rounding |
| 8 | How many rounds? | randomized rounding |
| 9 | A formula that splits the two algorithms | MAX-SAT, better of two |
| 10 | Scaling knapsack profits | FPTAS |
| 11 | Next Fit is tight | bin packing |
| 12 | Non-metric -center | gap-introducing reductions |
| 13 | Conditional or not? | PCP, UGC, assumptions |
Exercise 1: What a dual certifies
A primal-dual algorithm for weighted vertex cover returns a cover of weight 30 together with a feasible dual solution of value 18. What do you know about OPT, and what ratio does this run certify? Could the true ratio be 1?
Answer
, and the run certifies a ratio of at most . The true ratio could be 1 (if OPT = 30) or as large as (if OPT = 18).
Solution
By weak duality every feasible dual value is at most the LP optimum, which is at most OPT, so . The cover itself is feasible, so . Hence . Nothing more can be concluded without more information: the dual may be far from optimal (The Primal-Dual Method for Vertex Cover).
Exercise 2: Matchings on a path
Let be the path . What is the minimum vertex cover? Which maximal matchings make the matching algorithm return the largest and the smallest covers?
Answer
(for example ). The maximal matching gives all 6 vertices (ratio 2); the maximal matching gives (ratio ).
Solution
The matching has 3 disjoint edges, so , and covers all five edges. A maximal matching on a path with five edges has 2 or 3 edges: is maximal since , and each touch it. The algorithm returns twice the matching size, so 4 or 6 vertices. The program enumerates all maximal matchings.
from itertools import combinations
edges = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]
def is_matching(M):
return len({v for e in M for v in e}) == 2 * len(M)
maximal = [M for k in range(1, 4) for M in combinations(edges, k)
if is_matching(M) and all(not is_matching(M + (e,)) for e in edges if e not in M)]
for M in maximal:
print("maximal matching", M, "-> cover of size", 2 * len(M))maximal matching ((1, 2), (4, 5)) -> cover of size 4
maximal matching ((2, 3), (4, 5)) -> cover of size 4
maximal matching ((2, 3), (5, 6)) -> cover of size 4
maximal matching ((1, 2), (3, 4), (5, 6)) -> cover of size 6
Exercise 3: Greedy set cover by hand
, unit costs, sets , , , , . Run greedy (ties broken alphabetically), find OPT, and compare with the bound , where is the largest set size.
Answer
Greedy picks , then : 2 sets, which is optimal. .
Solution
covers 5 new elements, the most. Then covers , covers , covers , covers : greedy takes and everything is covered. One set cannot cover 8 elements, so . Greedy is often optimal on small instances; the bound is for the worst case (Greedy Set Cover).
Exercise 4: Christofides on a square
Four cities at the corners of a unit square, with Euclidean distances. Run Christofides' algorithm. What do the MST, the matching and the tour cost, and how does the tour compare with OPT?
Answer
MST 3 (three sides), two odd vertices (the ends of the path) at distance 1, matching 1, tour 4 = OPT.
Solution
All sides have length 1 and the diagonals , so any MST is a path of three sides, of cost 3. Its two endpoints are adjacent corners (a path through all four corners along three sides starts and ends at corners joined by the fourth side), so the minimum matching on them costs 1. Tree plus matching is the square itself, an Euler circuit of cost 4 that needs no shortcut, and no tour is shorter than the perimeter. The guarantee would allow (Christofides' Algorithm).
Exercise 5: Farthest-first on a line
Points on a line, , centres chosen among the points. Run farthest-first traversal starting at 0 and compare with the optimum.
Answer
Greedy picks 0, then 20: radius 10 (the point 10). The optimum is 9 (for example centres 1 and 11, or 2 and 11). Ratio .
Solution
From 0 the farthest point is 20. With centres 0 and 20, point 10 is at distance 10 from both, the worst. For the optimum, some point is always at distance at least 9: if 20 is not a centre, its nearest centre is at most 11, at distance at least 9; if 20 is a centre and the other centre is at most 2, point 11 is at distance at least 9 from both; and if the other centre is 10 or 11, point 0 is at distance at least 10. So , and centres 2 and 11 attain it. The program checks all 15 pairs.
from itertools import combinations
pts = [0, 1, 2, 10, 11, 20]
radius = lambda C: max(min(abs(p - c) for c in C) for p in pts)
best = min(radius(C) for C in combinations(pts, 2))
print("greedy {0, 20}: radius", radius((0, 20)))
print("optimum:", best, "attained by", [C for C in combinations(pts, 2) if radius(C) == best])greedy {0, 20}: radius 10
optimum: 9 attained by [(0, 11), (1, 11), (1, 20), (2, 11), (2, 20)]
The ratio is well within the guarantee of 2 (k-Center and Farthest-First Traversal).
Exercise 6: LPT on two machines
Jobs on machines. Compute the LPT schedule and OPT, and compare with Graham's bound.
Answer
LPT: and , makespan 7. OPT = 6 ( and ). Ratio : the bound is attained.
Solution
The two 3s go to different machines (loads 3, 3); the first 2 goes to machine 1 (5, 3); the second to machine 2 (5, 5); the third to either (7, 5). The total is 12, so , and attains it. Graham's bound for is : this is the tight family of Longest Processing Time First for .
Exercise 7: Rounding the 5-cycle
Unit weights on the cycle . Find the LP optimum, the result of threshold rounding, and OPT.
Answer
LP with everywhere; rounding takes all 5 vertices; OPT = 3. Ratio , integrality gap .
Solution
Summing the 5 edge constraints gives , so , attained by all halves (the unique optimum, which is also a vertex, as half-integrality predicts). Rounding at takes everything. An odd cycle of 5 needs 3 cover vertices (2 vertices cover at most 4 edges). See Rounding the Vertex Cover LP.
from scipy.optimize import linprog
edges = [(i, (i + 1) % 5) for i in range(5)]
res = linprog([1] * 5, A_ub=[[-1 if v in e else 0 for v in range(5)] for e in edges], b_ub=[-1] * 5,
bounds=[(0, 1)] * 5, method="highs-ds")
print("LP value", round(float(res.fun), 6), " x =", [round(float(x), 6) for x in res.x])
print("rounded cover size", sum(float(x) >= 0.5 for x in res.x))LP value 2.5 x = [0.5, 0.5, 0.5, 0.5, 0.5]
rounded cover size 5
Exercise 8: How many rounds?
In randomized rounding for set cover, suppose an element lies in exactly sets, each with . What is the probability that one round misses it, for ? With elements, how many rounds guarantee that all elements are covered with probability at least , using the bound per round?
Answer
: 0, , about . Rounds: with , i.e. , so 14 rounds.
Solution
The element is missed only if none of its sets is chosen, probability , which increases towards . After rounds the miss probability is at most ; the union bound over elements needs , so (Randomized Rounding for Set Cover).
Exercise 9: A formula that splits the two algorithms
Consider the clauses , , , (unit weights). Compute OPT, the expected value of the uniformly random assignment, an LP optimum, and the expected value of LP rounding for it.
Answer
OPT = 4 (). Random: . The LP has the integral optimum , value 4, and rounding it gives 4.
Solution
The all-true assignment satisfies all four clauses. The random assignment satisfies a clause of length with probability . The LP cannot exceed 4 and the integral point attains it; rounding an integral LP solution reproduces it. So on this formula LP rounding wins, and the better-of-two algorithm returns the optimum (MAX-SAT: Random Assignments, LP Rounding and the Better of Two). The unit clauses are what defeat the random assignment.
Exercise 10: Scaling knapsack profits
Four items with profits and . Compute , the rounded profits, and the maximum possible absolute loss.
Answer
; rounded profits ; loss at most .
Solution
, , , . Each item loses less than in the rounding, so any set loses less than , and gives the relative guarantee . Note that 60 and 55 become equal: the scaled instance can no longer tell them apart, which is where the loss comes from (A Knapsack FPTAS by Profit Scaling).
Exercise 11: Next Fit is tight
Construct, for every , an instance where Next Fit uses bins while suffice.
Answer
items alternating and (with ):
Solution
Next Fit puts in a bin; the next does not fit (), so every bin gets one pair: bins. The optimum pairs the halves into bins and puts the small items, of total size , into one more bin: . The ratio tends to 2.
def next_fit(items):
bins, room = 0, 0.0
for s in items:
if s > room + 1e-12:
bins, room = bins + 1, 1.0
room -= s
return bins
for n in [2, 5, 20]:
d = 1 / (2 * n)
items = [0.5, d] * (2 * n)
print(f"n = {n:2}: Next Fit {next_fit(items):2} bins, optimum {n + 1:2}, ratio {next_fit(items) / (n + 1):.3f}")n = 2: Next Fit 4 bins, optimum 3, ratio 1.333
n = 5: Next Fit 10 bins, optimum 6, ratio 1.667
n = 20: Next Fit 40 bins, optimum 21, ratio 1.905
Exercise 12: Non-metric k-center
Show that without the triangle inequality, -center has no -approximation for any constant unless P = NP.
Answer
Reduce from dominating set with distances 1 (edges) and (non-edges): OPT is 1 or .
Solution
Given and , set for edges and otherwise (). If has a dominating set of size , the optimal radius is 1; otherwise some vertex is not adjacent to any chosen centre, and the radius is . An -approximation returns radius at most exactly in the first case, deciding dominating set. With these distances violate the triangle inequality, which is why the metric case escapes with ratio 2 (Gap-Introducing Reductions).
Exercise 13: Conditional or not?
For each statement, give the assumption under which it is known: (a) MAX-E3SAT has no -approximation; (b) vertex cover has no -approximation; (c) set cover has no -approximation; (d) max-cut has no -approximation; (e) metric TSP has no PTAS.
Answer
(a) P NP (Håstad). (b) the UGC (Khot and Regev); under P NP only . (c) P NP (Dinur and Steurer). (d) the UGC (Khot, Kindler, Mossel and O'Donnell); under P NP only . (e) P NP (, Karpinski, Lampis and Schmied).
Solution
See the table in Tight Thresholds: MAX-3SAT, Clique and Set Cover and the list of consequences in The Unique Games Conjecture. A common mistake is to quote the UGC-based thresholds for vertex cover and max-cut as if they were known under P NP.
Test yourself
A minimization algorithm comes with a feasible dual of value and returns cost . Which ratio is certified?
- , since
- None without OPT
On jobs 3, 3, 2, 2, 2 and two machines, what are LPT's makespan and OPT?
- 6 and 6
- 7 and 6
- 7 and 7
- 8 and 6
Why does Next Fit use bins on the items ?
- Because the items are sorted
- Each bin receives and , and the next no longer fits, so the bin is closed
- Because items need their own bins
- Because OPT is