The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Tree and Cycle Detection Next: Two-Coloring Graphs Up: Applications of Graph Traversal Previous: Connected Components Tree and Cycle Detection Trees are connected, undirected graphs that do not contain cycles. They are perhaps the simplest interesting class of graphs. Testing whether a graph is a tree is straightforward using depth-first search. During search, every edge will be labeled either a tree edge or a back edge, so the graph is a tree if and only if there are no back edges. Since m=n-1 for any tree, this algorithm can be said to run in time linear in the number of vertices. If the graph is not a tree, it must contain a cycle. Such a cycle can be identified as soon as the first back edge (u,v) is detected. If (u,v) is a back edge, then there must be a path in the tree from v to u. Coupled with edge (u,v), this defines a cycle. Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE68.HTM [19/1/2003 1:29:09]
Two-Coloring Graphs Next: Topological Sorting Up: Applications of Graph Traversal Previous: Tree and Cycle Detection Two-Coloring Graphs In vertex coloring, we seek to assign a color to each vertex of a graph G such that no edge links two vertices of the same color. We can avoid all conflicts by assigning each vertex its own color. However, the goal is to use as few colors as possible. Vertex coloring problems arise often in scheduling applications, such as register allocation in compilers. See Section for a full treatment of vertex coloring algorithms and applications. A graph is bipartite if it can be colored without conflicts while using only two colors. Bipartite graphs are important because they arise often in practice and have more structure than arbitrary graphs. For example, consider the ``had-sex-with'' graph in a heterosexual world. Men have sex only with women, and vice versa. Thus gender defines a legal two-coloring. Irrespective of the accuracy of the model, it should be clear that bipartite graphs are simpler to work with than general graphs. But how can we find an appropriate two-coloring of a graph, thus separating the men from the women? Suppose we assume that the starting vertex is male. All vertices adjacent to this man must be female, assuming the graph is indeed bipartite. We can augment either breadth-first or depth-first search so that whenever we discover a new vertex, we color it the opposite of its parent. For each non-discovery edge, we check whether it links two vertices of the same color. Such a conflict means that the graph cannot be two-colored. However, we will have constructed a proper two-coloring whenever we terminate without conflict. We can assign the first vertex in any connected component to be whatever color/sex we wish. Although we can separate the men from the women, we can't tell them apart just using the graph. Next: Topological Sorting Up: Applications of Graph Traversal Previous: Tree and Cycle Detection Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE69.HTM [19/1/2003 1:29:09]
- Page 185 and 186: The Partition Problem Figure: Dynam
- Page 187 and 188: Approximate String Matching Next: L
- Page 189 and 190: Approximate String Matching The val
- Page 191 and 192: Longest Increasing Sequence Will th
- Page 193 and 194: Minimum Weight Triangulation Next:
- Page 195 and 196: Limitations of Dynamic Programming
- Page 197 and 198: War Story: Evolution of the Lobster
- Page 199 and 200: War Story: Evolution of the Lobster
- Page 201 and 202: War Story: What's Past is Prolog Ne
- Page 203 and 204: War Story: What's Past is Prolog th
- Page 205 and 206: War Story: Text Compression for Bar
- Page 207 and 208: War Story: Text Compression for Bar
- Page 209 and 210: Divide and Conquer Next: Fast Expon
- Page 211 and 212: Fast Exponentiation Next: Binary Se
- Page 213 and 214: Binary Search Next: Square and Othe
- Page 215 and 216: Exercises Next: Implementation Chal
- Page 217 and 218: Exercises whose denominations are ,
- Page 219 and 220: The Friendship Graph Next: Data Str
- Page 221 and 222: The Friendship Graph friendship gra
- Page 223 and 224: Data Structures for Graphs linked t
- Page 225 and 226: War Story: Getting the Graph ``Well
- Page 227 and 228: Traversing a Graph Next: Breadth-Fi
- Page 229 and 230: Breadth-First Search Next: Depth-Fi
- Page 231 and 232: Depth-First Search Next: Applicatio
- Page 233 and 234: Depth-First Search Next: Applicatio
- Page 235: Connected Components Next: Tree and
- Page 239 and 240: Topological Sorting Next: Articulat
- Page 241 and 242: Modeling Graph Problems Next: Minim
- Page 243 and 244: Modeling Graph Problems good line s
- Page 245 and 246: Minimum Spanning Trees ● Prim's A
- Page 247 and 248: Prim's Algorithm inserted edge (x,y
- Page 249 and 250: Kruskal's Algorithm a tree of weigh
- Page 251 and 252: Dijkstra's Algorithm Next: All-Pair
- Page 253 and 254: All-Pairs Shortest Path Next: War S
- Page 255 and 256: War Story: Nothing but Nets Next: W
- Page 257 and 258: War Story: Nothing but Nets ``You a
- Page 259 and 260: War Story: Dialing for Documents Ne
- Page 261 and 262: War Story: Dialing for Documents If
- Page 263 and 264: War Story: Dialing for Documents CO
- Page 265 and 266: Exercises Next: Implementation Chal
- Page 267 and 268: Exercises Prove the statement or gi
- Page 269 and 270: Backtracking report it. kth element
- Page 271 and 272: Constructing All Subsets Next: Cons
- Page 273 and 274: Constructing All Paths in a Graph N
- Page 275 and 276: Search Pruning Next: Bandwidth Mini
- Page 277 and 278: Bandwidth Minimization immediately
- Page 279 and 280: War Story: Covering Chessboards Nex
- Page 281 and 282: War Story: Covering Chessboards att
- Page 283 and 284: Heuristic Methods Mon Jun 2 23:33:5
- Page 285 and 286: Simulated Annealing Return S then u
Tree and Cycle Detection<br />
Next: Two-Coloring Graphs Up: Applications of Graph Traversal Previous: Connected Components<br />
Tree and Cycle Detection<br />
Trees are connected, undirected graphs that do not contain cycles. <strong>The</strong>y are perhaps the simplest<br />
interesting class of graphs. Testing whether a graph is a tree is straightforward using depth-first search.<br />
During search, every edge will be labeled either a tree edge or a back edge, so the graph is a tree if and<br />
only if there are no back edges. Since m=n-1 for any tree, this algorithm can be said to run in time linear<br />
in the number of vertices.<br />
If the graph is not a tree, it must contain a cycle. Such a cycle can be identified as soon as the first back<br />
edge (u,v) is detected. If (u,v) is a back edge, then there must be a path in the tree from v to u. Coupled<br />
with edge (u,v), this defines a cycle.<br />
<strong>Algorithm</strong>s<br />
Mon Jun 2 23:33:50 EDT 1997<br />
file:///E|/BOOK/BOOK2/NODE68.HTM [19/1/2003 1:29:09]