next up previous
Next: About this document Up: My Home Page

lec16-1.au Give an efficient algorithm to test if a graph is bipartite. Bipartite means the vertices can be colored red or black such that no edge links vertices of the same color.   

f301.5in

Suppose we color a vertex red - what color must its neighbors be? black!

We can augment either BFS or DFS when we first discover a new vertex, color it opposited its parents, and for each other edge, check it doesn't link two vertices of the same color. The first vertex in any connected component can be red or black!

Bipartite graphs arise in many situations, and special algorithms are often available for them. What is the interpretation of a bipartite ``had-sex-with'' graph?

How would you break people into two groups such that no group contains a pair of people who hate each other?

lec17-1.au Give an O(n) algorithm to test whether an undirected graph contains a cycle.   If you do a DFS, you have a cycle iff you have a back edge. This gives an O(n+m) algorithm. But where does the m go? If the graph contains more than n-1 edges, it must contain a cycle! Thus we never need look at more than n edges if we are given an adjacency list representation!

lec17-4.au Topological Sorting

A directed, acyclic graph is a directed graph with no directed cycles.    

f432in

A topological sort of a graph is an ordering on the vertices so that all edges go from left to right.

Only a DAG can have a topological sort.

f442in

Any DAG has (at least one) topological sort. lec17-5.au Applications of Topological Sorting

Topological sorting is often useful in scheduling jobs in their proper sequence. In general, we can use it to order things given constraints, such as a set of left-right constraints on the positions of objects.

Example: Dressing schedule from CLR.

Example: Identifying errors in DNA fragment assembly.  

Certain fragments are constrained to be to the left or right of other fragments, unless there are errors.

shortest-common-superstring-Lshortest-common-superstring-R

Solution - build a DAG representing all the left-right constraints. Any topological sort of this DAG is a consistant ordering. If there are cycles, there must be errors.

A DFS can test if a graph is a DAG (it is iff there are no back edges - forward edges are allowed for DFS on directed graph). lec17-6.au Algorithm

Theorem: Arranging vertices in decreasing order of DFS finishing time gives a topological sort of a DAG.

Proof: Consider any directed edge u,v, when we encounter it during the exploration of vertex u:

Thus we can do topological sorting in O(n+m) time. lec17-8.au Articulation Vertices

Suppose you are a terrorist, seeking to disrupt the telephone network. Which station do you blow up?    

f392in

An articulation vertex is a vertex of a connected graph whose deletion disconnects the graph.

Clearly connectivity is an important concern in the design of any network.  

Articulation vertices can be found in O(n(m+n)) - just delete each vertex to do a DFS on the remaining graph to see if it is connected. lec17-9.au A Faster O(n+m) DFS Algorithm

Theorem: In a DFS tree, a vertex v (other than the root) is an articulation vertex iff v is not a leaf and some subtree of v has no back edge incident until a proper ancestor of v.

f404in

Proof: (1) v is an articulation vertex tex2html_wrap_inline150 v cannot be a leaf.

Why? Deleting v must seperate a pair of vertices x and y. Because of the other tree edges, this cannot happen unless y is a decendant of v.

lec17-10.au

f424in

v separating x,y implies there is no back edge in the subtree of y to a proper ancestor of v.

(2) Conditions tex2html_wrap_inline172 v is a non-root articulation vertex. v separates any ancestor of v from any decendant in the appropriate subtree.

Actually implementing this test in O(n+m) is tricky - but believable once you accept this theorem.

lec17-12.au Strongly Connected Components

A directed graph is strongly connected iff there is a directed path between any two vertices.  

The strongly connected components of a graph is a partition of the vertices into subsets (maximal) such that each subset is strongly connected.

f453in

Observe that no vertex can be in two maximal components, so it is a partition.

strongpart

There is an amazingly elegant, linear time algorithm to find the strongly connected components of a directed graph, using DFS. lec17-13.au

This algorithm takes O(n+m), but why does it compute strongly connected components?

Lemma: If two vertices are in the same strong component, no path between them ever leaves the component.

f463in

Lemma: In any DFS forest, all vertices in the same strongly connected component are in the same tree.

Proof: Consider the first vertex v in the component to be discovered. Everything in the component is reachable from it, so we will traverse it before finishing with v. lec17-14.au What does DFS( tex2html_wrap_inline196 , v) Do?

It tells you what vertices have directed paths to v, while DFS( tex2html_wrap_inline200 ,v) tells what vertices have directed paths from v. But why must any vertex in the search tree of DFS( tex2html_wrap_inline206 , v) also have a path from u?

f473in

Because there is no edge from any previous DFS tree into the last tree!! Because we ordered the vertices by decreasing order of finish time, we can peel off the strongly connected components from right to left just be doing a DFS( tex2html_wrap_inline212 ).

lec17-16.au Example of Strong Components Algorithm

f453in

9, 10, 11, 12 can reach 9, oldest remaining finished is 5.

5, 6, 8 can reach 5, oldest remaining is 7.

7 can reach 7, oldest remaining is 1.

1, 2, 3 can reach 1, oldest remaining is 4.

4 can reach 4.

f484in




next up previous
Next: About this document Up: My Home Page

Steve Skiena
Tue Sep 15 16:51:34 EDT 1998