Sequencing Problems-Algorithms and Data Representation-Lecture Slides, Slides of Data Representation and Algorithm Design

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

2011/2012

Uploaded on 07/15/2012

saandeep
saandeep 🇮🇳

4.5

(6)

99 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Chapter 8
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.
8.5 Sequencing Problems
3
Hamiltonian Cycle
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
Hamiltonian Cycle
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.
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Sequencing Problems-Algorithms and Data Representation-Lecture Slides and more Slides Data Representation and Algorithm Design in PDF only on Docsity!

1

Chapter 8

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.

8.5 Sequencing Problems

3

Hamiltonian Cycle

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

Hamiltonian Cycle

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

Directed Hamiltonian Cycle

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

Directed Hamiltonian Cycle

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

3-SAT Reduces to Directed Hamiltonian Cycle

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

3-SAT Reduces to Directed Hamiltonian Cycle

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

The Longest Path t

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

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? All 13,509 cities in US with a population of at least 500 Reference: http://www.tsp.gatech.edu 15

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? Optimal TSP tour Reference: http://www.tsp.gatech.edu 16

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? 11,849 holes to drill in a programmed logic array Reference: http://www.tsp.gatech.edu

17

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? Optimal TSP tour Reference: http://www.tsp.gatech.edu 18

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? 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.

8.6 Partitioning Problems

20

3-Dimensional Matching

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

3-Dimensional Matching

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

3-Dimensional Matching

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.

8.7 Graph Coloring

28

3-Colorability

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

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

3-Colorability

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

3-Colorability

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

3-Colorability

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

Subset Sum

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

My Hobby

Randall Munro http://xkcd.com/c287.html 39

Scheduling With Release Times

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

8.10 A Partial Taxonomy of Hard Problems

41

Polynomial-Time Reductions

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

Extra Slides

43

Subset Sum (proof from book)

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

Partition

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.

  • v 1 = w 1 , v 2 = w 2 , …, vn = wn, vn+1 = 2 Σi wi - W, vn+2 = Σi wi + W  There exists a subset that sums to W iff there exists a partition since two new elements cannot be in the same partition. ▪ vn+2 = Σi wi + W vn+1 = 2 Σi wi - W Σi wi - W W subset A subset B ½ Σi vi

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.

Planarity Testing

simple planar graph can have at most 3n edges 50

Planar Graph 3-Colorability

Q. Is this planar graph 3-colorable? 51

Planar 3-Colorability and Graph 3-Colorability

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

Planar Graph 3-Colorability

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

Planar Graph 3-Colorability

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

Planar Graph 3-Colorability

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 k-Colorability

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.

Polynomial-Time Detour