









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Dr. Ameet Shashank at B R Ambedkar National Institute of Technology. Its relate to Data Representation and Algorithm Design course. Its main points are: Sequencing, Problems, Hamiltonian, Cycle, Genres, Intuition, Longest, Path, Traveling, Salesperson, Problem
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!










1
Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK.
3
HAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle Γ that contains every node in V. YES: vertices and faces of a dodecahedron. 4
HAM-CYCLE: given an undirected graph G = (V, E), does there exist a simple cycle Γ that contains every node in V. 1 3 5 1' 3' 2 4 2' 4' NO: bipartite graph with odd number of nodes.
5
DIR-HAM-CYCLE: given a digraph G = (V, E), does there exists a simple directed cycle Γ that contains every node in V? Claim. DIR-HAM-CYCLE ≤ (^) P HAM-CYCLE. Pf. Given a directed graph G = (V, E), construct an undirected graph G' with 3n nodes. v a b c d e vin aout bout cout din ein G (^) G' v vout 6
Claim. G has a Hamiltonian cycle iff G' does. Pf. ⇒ Suppose G has a directed Hamiltonian cycle Γ. Then G' has an undirected Hamiltonian cycle (same order). Pf. ⇐ Suppose G' has an undirected Hamiltonian cycle Γ'. Γ' must visit nodes in G' using one of following two orders: …, B, G, R, B, G, R, B, G, R, B, … …, B, R, G, B, R, G, B, R, G, B, … Blue nodes in Γ' make up directed Hamiltonian cycle Γ in G, or reverse of one. ▪ 7
Claim. 3-SAT ≤ (^) P DIR-HAM-CYCLE. Pf. Given an instance Φ of 3-SAT, we construct an instance of DIR- HAM-CYCLE that has a Hamiltonian cycle iff Φ is satisfiable. Construction. First, create graph that has 2n^ Hamiltonian cycles which correspond in a natural way to 2n^ possible truth assignments. 8
Construction. Given 3-SAT instance Φ with n variables xi and k clauses. Construct G to have 2n^ Hamiltonian cycles. Intuition: traverse path i from left to right ⇔ set variable xi = 1. s t 3k + 3 x 1 x 2 x 3
13
Lyrics. Copyright © 1988 by Daniel J. Barrett. Music. Sung to the tune of The Longest Time by Billy Joel. Woh-oh-oh-oh, find the longest path! Woh-oh-oh-oh, find the longest path! If you said P is NP tonight, There would still be papers left to write, I have a weakness, I'm addicted to completeness, And I keep searching for the longest path. The algorithm I would like to see Is of polynomial degree, But it's elusive: Nobody has found conclusive Evidence that we can find a longest path. I have been hard working for so long. I swear it's right, and he marks it wrong. Some how I'll feel sorry when it's done: GPA 2. Is more than I hope for. Garey, Johnson, Karp and other men (and women) Tried to make it order N log N. Am I a mad fool If I spend my life in grad school, Forever following the longest path? Woh-oh-oh-oh, find the longest path! Woh-oh-oh-oh, find the longest path! Woh-oh-oh-oh, find the longest path. t Recorded by Dan Barrett while a grad student at Johns Hopkins during a difficult algorithms final. 14
TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length ≤ D? All 13,509 cities in US with a population of at least 500 Reference: http://www.tsp.gatech.edu 15
TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length ≤ D? Optimal TSP tour Reference: http://www.tsp.gatech.edu 16
TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length ≤ D? 11,849 holes to drill in a programmed logic array Reference: http://www.tsp.gatech.edu
17
TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length ≤ D? Optimal TSP tour Reference: http://www.tsp.gatech.edu 18
TSP. Given a set of n cities and a pairwise distance function d(u, v), is there a tour of length ≤ D? HAM-CYCLE: given a graph G = (V, E), does there exists a simple cycle that contains every node in V? Claim. HAM-CYCLE ≤ (^) P TSP. Pf. Given instance G = (V, E) of HAM-CYCLE, create n cities with distance function TSP instance has tour of length ≤ n iff G is Hamiltonian. ▪ Remark. TSP instance in reduction satisfies Δ-inequality.
d ( u , v ) = 1 if ( u , v ) " E 2 if ( u , v ) # E
Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3-COLOR. Numerical problems: SUBSET-SUM, KNAPSACK.
20
3D-MATCHING. Given n instructors, n courses, and n times, and a list of the possible courses and times each instructor is willing to teach, is it possible to make an assignment so that all courses are taught at different times? Instructor Course Time Wayne COS 423 MW 11-12: Wayne COS 423 TTh 11-12: Wayne COS 226 TTh 11-12: Wayne COS 126 TTh 11-12: Tardos COS 523 TTh 3-4: Tardos COS 423 TTh 11-12: Tardos COS 423 TTh 3-4: Kleinberg COS 226 TTh 3-4: Kleinberg COS 226 MW 11-12: Kleinberg COS 423 MW 11-12:
25
Claim. Instance has a 3D-matching iff Φ is satisfiable. Detail. What are X, Y, and Z? Does each triple contain one element from each of X, Y, Z? x 1 x 2 x 3 core cleanup gadget true false clause 1 gadget clause 1 tips 26
Claim. Instance has a 3D-matching iff Φ is satisfiable. Detail. What are X, Y, and Z? Does each triple contain one element from each of X, Y, Z? x 1 x 2 x 3 core cleanup gadget clause 1 gadget clause 1 tips Basic genres. Packing problems: SET-PACKING, INDEPENDENT SET. Covering problems: SET-COVER, VERTEX-COVER. Constraint satisfaction problems: SAT, 3-SAT. Sequencing problems: HAMILTONIAN-CYCLE, TSP. Partitioning problems: 3D-MATCHING, 3 -COLOR. Numerical problems: SUBSET-SUM, KNAPSACK.
28
3-COLOR: Given an undirected graph G does there exists a way to color the nodes red, green, and blue so that no adjacent nodes have the same color? yes instance
29
Register allocation. Assign program variables to machine register so that no more than k registers are used and no two program variables that are needed at the same time are assigned to the same register. Interference graph. Nodes are program variables names, 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. Fact. 3-COLOR ≤ (^) P k-REGISTER-ALLOCATION for any constant k ≥ 3. 30
Claim. 3-SAT ≤ (^) P 3-COLOR. Pf. Given 3-SAT instance Φ, we construct an instance of 3-COLOR that is 3-colorable iff Φ is satisfiable. Construction. i. For each literal, create a node. ii. Create 3 new nodes T, F, B; connect them in a triangle, and connect each literal to B. iii. Connect each literal to its negation. iv. For each clause, add gadget of 6 nodes and 13 edges. to be described next 31
Claim. Graph is 3-colorable iff Φ is satisfiable. Pf. ⇒ Suppose graph is 3-colorable. Consider assignment that sets all T literals to true. (ii) ensures each literal is T or F. (iii) ensures a literal and its negation are opposites. T B F ! x 1 ! x 1 ! x 2 ! x 2 ! xn ! xn ! x 3 ! x 3 true (^) false base 32
Claim. Graph is 3-colorable iff Φ is satisfiable. Pf. ⇒ Suppose graph is 3-colorable. Consider assignment that sets all T literals to true. (ii) ensures each literal is T or F. (iii) ensures a literal and its negation are opposites. (iv) ensures at least one literal in each clause is T. T F B ! x 1 ! x 2 ! x 3 ! Ci = x 1 V x 2 V x 3 6-node gadget true false docsity.com
37
Construction. Given 3-SAT instance Φ with n variables and k clauses, form 2n + 2k decimal integers, each of n+k digits, as illustrated below. Claim. Φ is satisfiable iff there exists a subset that sums to W. Pf. No carries possible. ! C 1 = x " y " z C 2 = x " y " z C 3 = x " y " z dummies to get clause columns to sum to 4 y x z 0 0 0 0 1 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 x y z C 1 C 2 C 3 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 2 0 1 1 1 4 4 4 ¬ x ¬ y ¬ z W 10 200 100 1, 10, 10, 100, 100, 1, 2 1 20 111, 38
Randall Munro http://xkcd.com/c287.html 39
SCHEDULE-RELEASE-TIMES. Given a set of n jobs with processing time ti, release time ri, and deadline di, is it possible to schedule all jobs on a single machine such that job i is processed with a contiguous slot of ti time units in the interval [ri, di ]? Claim. SUBSET-SUM ≤ (^) P SCHEDULE-RELEASE-TIMES. Pf. Given an instance of SUBSET-SUM w 1 , …, wn, and target W, Create n jobs with processing time ti = wi, release time ri = 0, and no deadline (di = 1 + Σj wj). Create job 0 with t 0 = 1, release time r 0 = W, and deadline d 0 = W+1. 0 W W+1 S+ Can schedule jobs 1 to n anywhere but [W, W+1] job 0
41
3-SAT INDEPENDENT SET DIR-HAM-CYCLE VERTEX COVER Dick Karp (1972) 1985 Turing Award 3-SAT reduces to INDEPENDENT SET GRAPH 3-COLOR HAM-CYCLE TSP SUBSET-SUM PLANAR 3-COLOR^ SCHEDULING SET COVER packing and covering sequencing partitioning numerical constraint satisfaction
43
Construction. Let X ∪ Y ∪ Z be a instance of 3D-MATCHING with triplet set T. Let n = |X| = |Y| = |Z| and m = |T|. Let X = { x 1 , x 2 , x 3 x 4 }, Y = { y 1 , y 2 , y 3 , y 4 } , Z = { z 1 , z 2 , z 3 , z 4 } For each triplet t= (xi, yj, zk ) ∈ T, create an integer wt with 3n digits that has a 1 in positions i, n+j, and 2n+k. Claim. 3D-matching iff some subset sums to W = 111,…, 111. 100,010, 1,010,001, 1,010,000, 1,010,000, 10,001,000, 100,010,001, 10,000,010, 100,001,000, 100,100, x 2 y 2 z 4 x 4 y 3 z 4 x 3 y 1 z 2 x 3 y 1 z 3 x 3 y 1 z 1 x 4 y 4 z 4 x 1 y 2 z 3 x 2 y 4 z 2 x 1 y 1 z 1 Triplet ti wi 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 x 1 x 2 x 3 x 4 y 1 y 2 y 3 y 4 z 1 z 2 z 3 z 4 111,111,111, use base m+ 44
SUBSET-SUM. Given natural numbers w 1 , …, wn and an integer W, is there a subset that adds up to exactly W? PARTITION. Given natural numbers v 1 , …, vm , can they be partitioned into two subsets that add up to the same value? Claim. SUBSET-SUM ≤ (^) P PARTITION. Pf. Let W, w 1 , …, wn be an instance of SUBSET-SUM. Create instance of PARTITION with m = n+2 elements.
49 Planarity testing. [Hopcroft-Tarjan 1974] O(n). Remark. Many intractable graph problems can be solved in poly-time if the graph is planar; many tractable graph problems can be solved faster if the graph is planar.
simple planar graph can have at most 3n edges 50
Q. Is this planar graph 3-colorable? 51
Claim. PLANAR-3-COLOR ≤ (^) P PLANAR-GRAPH-3-COLOR. Pf sketch. Create a vertex for each region, and an edge between regions that share a nontrivial border. 52
Claim. W is a planar graph such that: In any 3-coloring of W, opposite corners have the same color. Any assignment of colors to the corners in which opposite corners have the same color extends to a 3-coloring of W. Pf. Only 3-colorings of W are shown below (or by permuting colors).
53
Claim. 3-COLOR ≤ (^) P PLANAR-GRAPH-3-COLOR. Pf. Given instance of 3-COLOR, draw graph in plane, letting edges cross. Replace each edge crossing with planar gadget W. In any 3-coloring of W, a ≠ a' and b ≠ b'. If a ≠ a' and b ≠ b' then can extend to a 3-coloring of W. a crossing a a' b b' a a' b b' gadget W 54
Claim. 3-COLOR ≤ (^) P PLANAR-GRAPH-3-COLOR. Pf. Given instance of 3-COLOR, draw graph in plane, letting edges cross. Replace each edge crossing with planar gadget W. In any 3-coloring of W, a ≠ a' and b ≠ b'. If a ≠ a' and b ≠ b' then can extend to a 3-coloring of W. multiple crossings a a' a' gadget W a W W W 55
PLANAR-2-COLOR. Solvable in linear time. PLANAR-3-COLOR. NP-complete. PLANAR-4-COLOR. Solvable in O(1) time. Theorem. [Appel-Haken, 1976] Every planar map is 4-colorable. Resolved century-old open problem. Used 50 days of computer time to deal with many special cases. First major theorem to be proved using computer. False intuition. If PLANAR-3-COLOR is hard, then so is PLANAR-4-COLOR and PLANAR-5-COLOR. 56 Graph minor theorem. [Robertson-Seymour 1980s] Corollary. There exist an O(n^3 ) algorithm to determine if a graph can be embedded in the torus in such a way that no two edges cross. Pf of theorem. Tour de force.