Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33.

Similar presentations


Presentation on theme: "CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33."— Presentation transcript:

1 CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33

2 Graph Coloring Given a map, can it be colored using 3 colors so that no adjacent regions have the same color? YES instance

3 Graph Coloring Given a map, can it be colored using 3 colors so that no adjacent regions have the same color? NO instance

4 Graph Coloring We seek to assign a color to each node of a graph G so that if (u, v) is an edge, then u and v are assigned different colors; and the goal is to do this while using a small set of colors A k-coloring of G is a function f:V  {1, 2, …, k} so that for every edge (u, v), we have f(u)  f(v). If G has a k-coloring, we say that it is a k- colorable graph –When is a graph 2-colorable? Given a graph G and a bound k, does G have a k-coloring?

5 Applications: Scheduling Example: schedule final exams and, being very considerate, avoid having a student do more than one exam a day What is the least number of days you need to schedule all the exams? (DONE IN CLASS) c1c2c3c4c5c6c7 c1 ***** c2 *** c3 *** c4 **** c5 ** c6 **** c7 *** courses 7 and 2 have at least one student in common

6 Applications: Register Allocation Assign program variables to machine registers 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

7 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

8 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 –For each literal, create a node –Create 3 new nodes T, F, B; connect them in a triangle, and connect each literal to B –Connect each literal to its negation –For each clause, add gadget of 6 nodes and 13 edges T B F true false base

9 3-Colorability B 6-node gadget T F true false base


Download ppt "CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 33."

Similar presentations


Ads by Google