18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Two-Coloring Graphs<br />

Next: Topological Sorting Up: Applications of Graph Traversal Previous: Tree and Cycle Detection<br />

Two-Coloring Graphs<br />

In vertex coloring, we seek to assign a color to each vertex of a graph G such that no edge links two<br />

vertices of the same color. We can avoid all conflicts by assigning each vertex its own color. However,<br />

the goal is to use as few colors as possible. Vertex coloring problems arise often in scheduling<br />

applications, such as register allocation in compilers. See Section for a full treatment of vertex<br />

coloring algorithms and applications.<br />

A graph is bipartite if it can be colored without conflicts while using only two colors. Bipartite graphs<br />

are important because they arise often in practice and have more structure than arbitrary graphs. For<br />

example, consider the ``had-sex-with'' graph in a heterosexual world. Men have sex only with women,<br />

and vice versa. Thus gender defines a legal two-coloring. Irrespective of the accuracy of the model, it<br />

should be clear that bipartite graphs are simpler to work with than general graphs.<br />

But how can we find an appropriate two-coloring of a graph, thus separating the men from the women?<br />

Suppose we assume that the starting vertex is male. All vertices adjacent to this man must be female,<br />

assuming the graph is indeed bipartite.<br />

We can augment either breadth-first or depth-first search so that whenever we discover a new vertex, we<br />

color it the opposite of its parent. For each non-discovery edge, we check whether it links two vertices of<br />

the same color. Such a conflict means that the graph cannot be two-colored. However, we will have<br />

constructed a proper two-coloring whenever we terminate without conflict. We can assign the first vertex<br />

in any connected component to be whatever color/sex we wish. Although we can separate the men from<br />

the women, we can't tell them apart just using the graph.<br />

Next: Topological Sorting Up: Applications of Graph Traversal Previous: Tree and Cycle Detection<br />

<strong>Algorithm</strong>s<br />

Mon Jun 2 23:33:50 EDT 1997<br />

file:///E|/BOOK/BOOK2/NODE69.HTM [19/1/2003 1:29:09]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!