IntractabilityIII 207
IntractabilityIII 207
Coping strategies.
i. Design algorithms for special cases of the problem. using greedy,
dynamic programming,
ii. Design approximation algorithms or heuristics. divide-and-conquer, and
network flow algorithms!
iii. Design algorithms that may take exponential time.
2
I NTRACTABILITY III
Fact. A tree has at least one node that is a leaf (degree = 1).
4
Independent set on trees: greedy algorithm
INDEPENDENT-SET-IN-A-FOREST(F)
_________________________________ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ _____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ___
S ← ∅.
WHILE (F has at least 1 edge)
Let v be a leaf node and let (u, v) be the lone edge incident to v.
S ← S ∪ { v }.
F ← F – { u, v }. delete both u and v (including all incident edges)
5
Intractability III: quiz 1
How might the greedy algorithm fail if the graph is not a tree/forest?
A. Might get stuck. (resulting) graph may not have a leaf node
6
Weighted independent set on trees
u weight = huge
7
Weighted independent set on trees
overlapping r
subproblems
Bellman equation.
v w x
children(u) = { v, w, x }
8
Intractability III: quiz 2
A. Preorder.
C. Level order.
9
Weighted independent set on trees: dynamic-programming
algorithm
WEIGHTED-INDEPENDENT-SET-IN-A-TREE (T)
_________________________________ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ _____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ___
10
NP-hard problems on trees: context
Independent set on trees. Tractable because we can find a node that breaks
the communication among the subproblems in different subtrees.
T T
T1
2 3
11
I NTRACTABILITY III
Def. A graph is planar if it can be embedded in the plane in such a way that
no two edges cross.
planar
13
Planarity testing
14
Problems on planar graphs
15
Planar graph 3-colorability
16
Planar map 3-colorability
yes instance
17
Planar map 3-colorability
no instance
18
Planar graph and map 3-colorability reduce to one another
19
Planar 3-colorability is NP-complete
Pf.
・Easy to see that PLANAR-3-COLOR ∈ NP.
・We show 3-COLOR ≤ P PLANAR-3-COLOR.
・Given 3-COLOR instance G, we construct an instance of
PLANAR-3-COLOR that is 3-colorable iff G is 3-colorable.
20
Planar map k-colorability
Remarks.
・Appel–Haken yields O(n4) algorithm to 4-color of a planar map.
・Best known: O(n2) to 4-color; O(n) to 5-color.
・Determining whether 3 colors suffice is NP-complete.
25
Poly-time special cases of NP-hard problems
Interference graph. Nodes are “live ranges.” Edge (u, v) if there exists an
operation where both u and v are “live” at the same time.
29
A useful property
v
k=3 k=2
Push v on stack
31
Chaitin’s algorithm
32
I NTRACTABILITY III
r-approximation algorithm.
・Runs in polynomial time.
・Applies to arbitrary instances of the problem.
・Guaranteed to find a solution within ratio r of true optimum.
Ex. Given a graph G, can find a vertex cover that uses ≤ 2 OPT(G) vertices
in O(m + n) time.
34
Vertex cover
35
Vertex cover: greedy algorithm
GREEDY-VERTEX-COVER(G)
_________________________________ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ _____ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ __
S ← ∅.
E′ ← E.
WHILE (E′ ≠ ∅) every vertex cover must take
at least one of these; we take both
Let (u, v) ∈ E′ be an arbitrary edge.
M ← M ∪ {(u, v)}. M is a matching
S ← S ∪ {u} ∪ {v}.
Delete from E′ all edges incident to either u or v.
RETURN S.
36
Intractability III: quiz 3
Given a graph G, let M be any matching and let S be any vertex cover. Which
of the following must be true?
A. ⎢ M ⎢ ≤ ⎢S ⎢
B. ⎢ S ⎢ ≤ ⎢M ⎢
C. ⎢ S ⎢ = ⎢M ⎢
Pf.
・S is a vertex cover. delete edge only after it’s already covered
・M is a matching. when (u, v) added to M, all edges incident to either u or v are deleted
・⎢ S ⎢ = 2 ⎢ M ⎢ ≤ 2 ⎢ S * ⎢. ▪
weak duality
38
Vertex cover inapproximability
39
I NTRACTABILITY III
Knapsack problem.
・Given n objects and a knapsack.
・Item i has value vi > 0 and weighs wi > 0. we assume w ≤ W for each i
i
1 1 1
2 6 2
3 18 5
4 22 6
5 28 7
41
Knapsack is NP-complete
42
Knapsack problem: dynamic programming I
Def. OPT(i, w) = max value subset of items 1,..., i with weight limit w.
Def. OPT(i, v) = min weight of a knapsack for which we can obtain a solution
of value ≥ v using a subset of items 1,..., i.
44
Knapsack problem: dynamic programming II
45
Knapsack problem: poly-time approximation scheme
1 934221 1 1 1 1
2 5956342 2 2 6 2
3 18 5
1781001
3 5
3 4 22 6
2121780 5 28 7
4 6
0
original instance (W = 11) rounded instance (W = 11)
2734319
5 7
9
46
Knapsack problem: poly-time approximation scheme
47
Knapsack problem: poly-time approximation scheme
subset containing
always round up only the item
of largest value
solve rounded
instance optimally
choosing S* = { max }
never round up
by more than θ
|S| ≤ n
thus
θ = ε vmax / 2n
vmax ≤ 2 Σi ∈ S vi
48
Knapsack problem: poly-time approximation scheme
Theorem. For any ε > 0, the rounding algorithm computes a feasible solution
whose value is within a (1 + ε) factor of the optimum in O(n3 / ε) time.
Pf.
・We have already proved the accuracy bound.
・Dynamic program II running time is , where
49
I NTRACTABILITY III
52
I NTRACTABILITY III
Given the locations of n Pokémon, find shortest tour to collect them all.
63
Traveling salesperson problem
TSP. Given a set of n cities and a pairwise distance function d(u, v),
is there a tour of length ≤ D ?
can view as a complete graph
TSP. Given a set of n cities and a pairwise distance function d(u, v),
is there a tour of length ≤ D ?
66
Hamilton cycle reduces to traveling salesperson problem
TSP. Given a set of n cities and a pairwise distance function d(u, v),
is there a tour of length ≤ D ?
67
Intractability III: quiz 4
68
Exponential algorithm for TSP: dynamic programming
Theorem. [Held–Karp, Bellman 1962] TSP can be solved in O(n2 2n) time.
70
Exponential algorithm for TSP: dynamic programming
Theorem. [Held–Karp, Bellman 1962] TSP can be solved in O(n2 2n) time.
v s
・The values c(s, v, X) can be computed in increasing
order of the cardinality of X. ▪
71
22-city TSP instance takes 1,000 years
222 = 4,194,304
22! = 1,124,000,727,777,607,680,000 ~ 10 21
73
Concorde TSP solver
74
Euclidean traveling salesperson problem
Euclidean TSP. Given n points in the plane and a real number L, is there a
tour that visit every city exactly once that has distance ≤ L ?
Theorem. [Arora 1998, Mitchell 1999] Given n points in the plane, for any
constant ε > 0: there exists a poly-time algorithm to find a tour whose length
is at most (1 + ε) times that of the optimal tour.
76