1 Chapter 10 Extending the Limits of Tractability Slides by Kevin Wayne. 2005 Pearson-Addison Wesley. All rights reserved.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
Introduction to Algorithms
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
CSCI 256 Data Structures and Algorithm Analysis Lecture 22 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
Parallel Scheduling of Complex DAGs under Uncertainty Grzegorz Malewicz.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
CPSC 689: Discrete Algorithms for Mobile and Wireless Systems Spring 2009 Prof. Jennifer Welch.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
Approximation Algorithms
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Odds and Ends HP ≤ p HC (again) –Turing reductions Strong NP-completeness versus Weak NP-completeness Vertex Cover to Hamiltonian Cycle.
Coloring Algorithms and Networks. Coloring2 Graph coloring Vertex coloring: –Function f: V  C, such that for all {v,w}  E: f(v)  f(w) Chromatic number.
Randomness in Computation and Communication Part 1: Randomized algorithms Lap Chi Lau CSE CUHK.
1 Introduction to Approximation Algorithms Lecture 15: Mar 5.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
9/3/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Guest lecturer: Martin Furer Algorithm Design and Analysis L ECTURE.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Approximating Minimum Bounded Degree Spanning Tree (MBDST) Mohit Singh and Lap Chi Lau “Approximating Minimum Bounded DegreeApproximating Minimum Bounded.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 27.
Chapter 15 Approximation Algorithm Introduction Basic Definition Difference Bounds Relative Performance Bounds Polynomial approximation Schemes Fully Polynomial.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33.
EMIS 8373: Integer Programming NP-Complete Problems updated 21 April 2009.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Approximation Algorithms These lecture slides are adapted from CLRS.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Chapter 8 NP and Computational Intractability Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Unit 9: Coping with NP-Completeness
NP-Complete Problems. Running Time v.s. Input Size Concern with problems whose complexity may be described by exponential functions. Tractable problems.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness and course wrap up.
1 Chapter 4 Minimum Spanning Trees Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CS 3343: Analysis of Algorithms Lecture 25: P and NP Some slides courtesy of Carola Wenk.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 29.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
CPS Computational problems, algorithms, runtime, hardness (a ridiculously brief introduction to theoretical computer science) Vincent Conitzer.
10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network.
28.
CSC 413/513: Intro to Algorithms
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
Lecture. Today Problem set 9 out (due next Thursday) Topics: –Complexity Theory –Optimization versus Decision Problems –P and NP –Efficient Verification.
CSE 421 Algorithms Richard Anderson Lecture 27 NP-Completeness Proofs.
Robust Graph Coloring on Paths Ralf Ollig. ROBUST GRAPH COLORING PROBLEM Undirected Graph G =(V,E) Undirected Graph G =(V,E) Positive integer k ≥ χ(G)
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
Approximation Algorithms by bounding the OPT Instructor Neelima Gupta
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 3.
COSC 3101A - Design and Analysis of Algorithms 14 NP-Completeness.
Algorithm Design and Analysis
Lectures on Network Flows
Richard Anderson Lecture 25 NP-Completeness
Coping With NP-Completeness
Vertex Covers, Matchings, and Independent Sets
Chapter 8 NP and Computational Intractability
Linear Programming Duality, Reductions, and Bipartite Matching
Problem Solving 4.
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Coping With NP-Completeness
Presentation transcript:

1 Chapter 10 Extending the Limits of Tractability Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

2 Coping With NP-Completeness Q. Suppose I need to solve an NP-complete problem. What should I do? A. Theory says you're unlikely to find poly-time algorithm. Must sacrifice one of three desired features. n Solve problem to optimality. n Solve problem in polynomial time. n Solve arbitrary instances of the problem. This lecture. Solve some special cases of NP-complete problems that arise in practice.

10.1 Finding Small Vertex Covers

4 Vertex Cover VERTEX COVER : Given a graph G = (V, E) and an integer k, is there a subset of vertices S  V such that |S|  k, and for each edge (u, v) either u  S, or v  S, or both k = 4 S = { 3, 6, 7, 10 }

5 Finding Small Vertex Covers Q. What if k is small? Brute force. O(k n k+1 ). n Try all C(n, k) = O(n k ) subsets of size k. n Takes O(k n) time to check whether a subset is a vertex cover. Goal. Limit exponential dependency on k, e.g., to O(2 k k n). Ex. n = 1,000, k = 10. Brute. k n k+1 =  infeasible. Better. 2 k k n = 10 7  feasible. Remark. If k is a constant, algorithm is poly-time; if k is a small constant, then it's also practical.

6 Finding Small Vertex Covers Claim. Let u-v be an edge of G. G has a vertex cover of size  k iff at least one of G  { u } and G  { v } has a vertex cover of size  k-1. Pf.  n Suppose G has a vertex cover S of size  k. n S contains either u or v (or both). Assume it contains u. n S  { u } is a vertex cover of G  { u }. Pf.  n Suppose S is a vertex cover of G  { u } of size  k-1. n Then S  { u } is a vertex cover of G. ▪ Claim. If G has a vertex cover of size k, it has  k(n-1) edges. Pf. Each vertex covers at most n-1 edges. ▪ delete v and all incident edges

7 Finding Small Vertex Covers: Algorithm Claim. The following algorithm determines if G has a vertex cover of size  k in O(2 k kn) time. Pf. n Correctness follows previous two claims. n There are  2 k+1 nodes in the recursion tree; each invocation takes O(kn) time. ▪ boolean Vertex-Cover(G, k) { if (G contains no edges) return true if (G contains  kn edges) return false let (u, v) be any edge of G a = Vertex-Cover(G - {u}, k-1) b = Vertex-Cover(G - {v}, k-1) return a or b }

8 Finding Small Vertex Covers: Recursion Tree k k-1 k k - i

10.2 Solving NP-Hard Problems on Trees

10 Independent Set on Trees Independent set on trees. Given a tree, find a maximum cardinality subset of nodes such that no two share an edge. Fact. A tree on at least two nodes has at least two leaf nodes. Key observation. If v is a leaf, there exists a maximum size independent set containing v. Pf. (exchange argument) n Consider a max cardinality independent set S. n If v  S, we're done. n If u  S and v  S, then S  { v } is independent  S not maximum. n IF u  S and v  S, then S  { v }  { u } is independent. ▪ v u degree = 1

11 Independent Set on Trees: Greedy Algorithm Theorem. The following greedy algorithm finds a maximum cardinality independent set in forests (and hence trees). Pf. Correctness follows from the previous key observation. ▪ Remark. Can implement in O(n) time by considering nodes in postorder. Independent-Set-In-A-Forest(F) { S   while (F has at least one edge) { Let e = (u, v) be an edge such that v is a leaf Add v to S Delete from F nodes u and v, and all edges incident to them. } return S }

12 Weighted Independent Set on Trees Weighted independent set on trees. Given a tree and node weights w v > 0, find an independent set S that maximizes  v  S w v. Observation. If (u, v) is an edge such that v is a leaf node, then either OPT includes u, or it includes all leaf nodes incident to u. Dynamic programming solution. Root tree at some node, say r. n OPT in (u) = max weight independent set rooted at u, containing u. n OPT out (u) = max weight independent set rooted at u, not containing u. r u vw x children(u) = { v, w, x }

13 Independent Set on Trees: Greedy Algorithm Theorem. The dynamic programming algorithm find a maximum weighted independent set in trees in O(n) time. Pf. Takes O(n) time since we visit nodes in postorder and examine each edge exactly once. ▪ Weighted-Independent-Set-In-A-Tree(T) { Root the tree at a node r foreach (node u of T in postorder) { if (u is a leaf) { M in [u] = w u M out [u] = 0 } else { M in [u] =  v  children(u) M out [v] + w v M out [u] =  v  children(u) max(M out [v], M in [v]) } return max(M in [r], M out [r]) } ensures a node is visited after all its children

14 Context Independent set on trees. This structured special case is tractable because we can find a node that breaks the communication among the subproblems in different subtrees. Graphs of bounded tree width. Elegant generalization of trees that: n Captures a rich class of graphs that arise in practice. n Enables decomposition into independent pieces. uu see Chapter 10.4, but proceed with caution

10.3 Circular Arc Coloring

16 Wavelength-Division Multiplexing Wavelength-division multiplexing (WDM). Allows m communication streams (arcs) to share a portion of a fiber optic cable, provided they are transmitted using different wavelengths. Ring topology. Special case is when network is a cycle on n nodes. Bad news. NP-complete, even on rings. Brute force. Can determine if k colors suffice in O(k m ) time by trying all k-colorings. Goal. O(f(k))  poly(m, n) on rings f b c d a e n = 4, m = 6

17 Wavelength-Division Multiplexing Wavelength-division multiplexing (WDM). Allows m communication streams (arcs) to share a portion of a fiber optic cable, provided they are transmitted using different wavelengths. Ring topology. Special case is when network is a cycle on n nodes. Bad news. NP-complete, even on rings. Brute force. Can determine if k colors suffice in O(k m ) time by trying all k-colorings. Goal. O(f(k))  poly(m, n) on rings f b c d a e n = 4, m = 6

18 Review: Interval Coloring Interval coloring. Greedy algorithm finds coloring such that number of colors equals depth of schedule. Circular arc coloring. n Weak duality: number of colors  depth. n Strong duality does not hold. h c a e f g i j d b maximum number of streams at one location max depth = 2 min colors = 3

19 (Almost) Transforming Circular Arc Coloring to Interval Coloring Circular arc coloring. Given a set of n arcs with depth d  k, can the arcs be colored with k colors? Equivalent problem. Cut the network between nodes v 1 and v n. The arcs can be colored with k colors iff the intervals can be colored with k colors in such a way that "sliced" arcs have the same color. colors of a', b', and c' must correspond to colors of a", b", and c" v1v1 v2v2 v4v4 v3v3 v1v1 v2v2 v3v3 v4v4 v0v0 v0v0 v0v0

20 Circular Arc Coloring: Dynamic Programming Algorithm Dynamic programming algorithm. n Assign distinct color to each interval which begins at cut node v 0. n At each node v i, some intervals may finish, and others may begin. n Enumerate all k-colorings of the intervals through v i that are consistent with the colorings of the intervals through v i-1. n The arcs are k-colorable iff some coloring of intervals ending at cut node v 0 is consistent with original coloring of the same intervals c' b' a' e b' d e f d e f c" a" b" c" v0v0 v1v1 v2v2 v3v3 v4v4 v0v0 yes

21 Circular Arc Coloring: Running Time Running time. O(k!  n). n n phases of the algorithm. n Bottleneck in each phase is enumerating all consistent colorings. n There are at most k intervals through v i, so there are at most k! colorings to consider. Remark. This algorithm is practical for small values of k (say k = 10) even if the number of nodes n (or paths) is large.

Extra Slides

Vertex Cover in Bipartite Graphs

24 Vertex Cover Vertex cover. Given an undirected graph G = (V, E), a vertex cover is a subset of vertices S  V such that for each edge (u, v)  E, either u  S or v  S or both ' 3' 5' 2 4 2' 4' S = { 3, 4, 5, 1', 2' } |S| = 5

25 Vertex Cover Weak duality. Let M be a matching, and let S be a vertex cover. Then, |M|  |S|. Pf. Each vertex can cover at most one edge in any matching ' 3' 5' 2 4 2' 4' M = 1-2', 3-1', 4-5' |M| = 3

26 Vertex Cover: König-Egerváry Theorem König-Egerváry Theorem. In a bipartite graph, the max cardinality of a matching is equal to the min cardinality of a vertex cover ' 3' 5' 2 4 2' 4' M* = 1-1', 2-2', 3-3', 5-5' |M*| = 4 S* = { 3, 1', 2', 5'} |S*| = 4

27 Vertex Cover: Proof of König-Egerváry Theorem König-Egerváry Theorem. In a bipartite graph, the max cardinality of a matching is equal to the min cardinality of a vertex cover. n Suffices to find matching M and cover S such that |M| = |S|. n Formulate max flow problem as for bipartite matching. n Let M be max cardinality matching and let (A, B) be min cut. s ' 3' 5' t 2 4 2' 4' 1 1 

28 Vertex Cover: Proof of König-Egerváry Theorem König-Egerváry Theorem. In a bipartite graph, the max cardinality of a matching is equal to the min cardinality of a vertex cover. n Suffices to find matching M and cover S such that |M| = |S|. n Formulate max flow problem as for bipartite matching. n Let M be max cardinality matching and let (A, B) be min cut. n Define L A = L  A, L B = L  B, R A = R  A, R B = R  B. n Claim 1. S = L B  R A is a vertex cover. – consider (u, v)  E – u  L A, v  R B impossible since infinite capacity – thus, either u  L B or v  R A or both n Claim 2. |S| = |M|. – max-flow min-cut theorem  |M| = cap(A, B) – only edges of form (s, u) or (v, t) contribute to cap(A, B) – |M| = cap(A, B) = |L B | + |R A | = |S|. ▪

Register Allocation

30 Register Allocation Register. One of k of high-speed memory locations in computer's CPU. Register allocator. Part of an optimizing compiler that controls which variables are saved in the registers as compiled program executes. Interference graph. Nodes are "live ranges" (variables or temporaries). There is an edge between u and v if there exists an operation where both u and v are "live" at the same time. Observation. [Chaitin, 1982] Can solve register allocation problem iff interference graph is k-colorable. Spilling. If graph is not k-colorable (or we can't find a k-coloring), we "spill" certain variables to main memory and swap back as needed. typically infrequently used variables that are not in inner loops say 32

31 A Useful Property Remark. Register allocation problem is NP-hard. Key fact. If a node v in graph G has fewer than k neighbors, G is k-colorable iff G  { v } is k-colorable. Pf. Delete node v from G and color G  { v }. n If G  { v } is not k-colorable, then neither is G. n If G  { v } is k-colorable, then there is at least one remaining color left for v. ▪ delete v and all incident edges k = 2 G is 2-colorable even though all nodes have degree 2 v k = 3

32 Chaitin's Algorithm Vertex-Color(G, k) { while (G is not empty) { Pick a node v with fewer than k neighbors Push v on stack Delete v and all its incident edges } while (stack is not empty) { Pop next node v from the stack Assign v a color different from its neighboring nodes which have already been colored } say, node with fewest neighbors

33 Chaitin's Algorithm Theorem. [Kempe 1879, Chaitin 1982] Chaitin's algorithm produces a k-coloring of any graph with max degree k-1. Pf. Follows from key fact since each node has fewer than k neighbors. Remark. If algorithm never encounters a graph where all nodes have degree  k, then it produces a k-coloring. Practice. Chaitin's algorithm (and variants) are extremely effective and widely used in real compilers for register allocation. algorithm succeeds in k-coloring many graphs with max degree  k