New version page

UW-Madison CS 240 - Lecture 18 - Digraphs

This preview shows page 1-2 out of 7 pages.

View Full Document
View Full Document

End of preview. Want to read all 7 pages?

Upload your study docs or become a GradeBuddy member to access this document.

View Full Document
Unformatted text preview:

CS/Math 240: Introduction to Discrete Mathematics 4/5/2011Lecture 18 : DigraphsInstructor: Dieter van Melkebeek Scribe: Dalibor Zelen´yDRAFTLast time we discussed relations and used graphs and digraphs to represent them. Afterwards,we started focusing on directed graphs, and we will finish that discussion today. After that we willstart looking at graphs whose edges don’t have a direction.18.1 Directed GraphsRecall that a digraph G is a pair of sets V and E, where V is the set of vertices and E is a multisetof edges. The edges are elements of the Cartesian product V ×V . If the edge multiset E is actuallya set, we say G is simple, and in this case G represents some relation.18.1.1 Transitive Closure of a Directed GraphLast time we defined what we mean by a path and a cycle in a directed graph. The notion of apath also induces a relation R on V . In particular, uRv if there is a path from u to v in G. Thisrelation is called the transitive closure of G.Transitive closure is reflexive. This is because a path from v ∈ V to itself is one where westart at v and stay put. This path has length zero and doesn’t require any edges, which means it’spresent in every graph, even in one without any edges.Transitive closure is not symmetric. The simplest counterexample is the graph with 2 verticesu and v and one edge (u, v). There is a path from u to v, but there is no path from v to u. Wewill discuss graphs for which the transitive closure is symmetric in the second part of this lecture.Transitive closure is, as the name suggests, transitive. Indeed, let u, v, w ∈ V , and supposethere is a path e1, e2, . . . , erfrom u to v, and a path f1, f2, . . . , fsfrom v to w. Then the sequenceof edges e1, e1, . . . , er, f1, f2, . . . , fris a path from u to w.18.1.2 Directed Acyclic GraphsA directed graph is acyclic if it contains no cycles. Se call such a graph a directed acyclic graph, orDAG for short.Directed acyclic graphs describe many real life situations. For example, consider registeringfor classes. Some courses have other courses as prerequisites. We can model this relation on theset of courses using a direc ted graph. Each course has a cor responding vertex in the graph, andthere is an edge from the vertex representing course c1to a vertex representing course c2if c1isa prerequisite for c2. If there is a cycle in this graph, we won’t be able to take any course whosecorresponding vertex is on that cycle, or any course whose corresponding vertex lies on a path fromsome vertex in that cyc le. Thus, the graph representing the “prerequisite” relation better be adirected acyclic graph.Other examples of relations represented by directed acyclic graphs are dependencies betweendifferent pieces of software on a computer. Again, if there are circular dependencies, we would notbe able to install some software.1Lecture 18: Digraphs 18.1. Directed GraphsThe same thing goes for programming parts of a bigger project. We first need to code up thesmall parts before we can get the bigger parts to work. If there is a circular dependency, we maynot be able to finish our program, or, at the very least, we will have to co de up a significant portionof it before we can test its functionality (this often suggests that we designed the program poorly).Example 18.1: Let’s consider a more mundane problem: getting dressed. The graph of the “putthis on before you put that on” relation is in Figure 18.1. Piece of clothing a is related to piece ofclothing b if you need to put on a before putting on b. For example, you first need to put on yourright sock before you put on your right shoe. This is indicated by an edge going from the vertexlabeled “right sock” to the vertex labeled “right shoe” in Figure 18.1. Observe that the graph isacyclic. If it were cyclic, we would not be able to get dressed. ⊠left shoeleft sockright shoeright sockbeltpantsunderwearjacketsweatershirtFigure 18.1: Graph of the clothing dependency relation.A directed acyclic graph has no edges of the form (v, v) because such an edge would form acycle of length 1. We now show that we can take any directed acyclic graph and arrange all itsvertices on one line so that if u, v ∈ V and (u, v) ∈ E, then the vertex u is “to the left” of thevertex v. In other words, all arrows in a picture representing that graph point from the left to theright. More formally, we show that every directed acyclic graph has a topological ordering.Definition 18.1. A topological ordering of a graph G = (V, E) is a total order ≤ on V such thatif (u, v) ∈ E for two different vertices u, v ∈ V , then u ≤ v.Theorem 18.2. Every directed acyclic graph has a topological ordering.Before we prove Theorem 18.2, let’s see an example involving the graph from Figure 18.1.Example 18.2: Consider the rearr angement of the nodes of the graph from Figure 18.1 shown inFigure 18.2. Notice that all edges go from left to right, so we have a topological ordering of thegraph from Figure 18.1.More formally, the relation ≤ on the set of vertices defined by u ≤ v if u is to the left of v inFigure 18.2 satisfies (u, v) ∈ E ⇒ u ≤ v for all u, v ∈ V such that u 6= v, and is a total order.Notice that if we go through the vertices in the graph in Figure 18.2 from left to right and puton a piece of clothing when we reach its corresponding vertex, we successfully get dressed. ⊠To prove Theorem 18.2, we need to define the following properties of vertices.Definition 18.3. Let G = (V, E) be a graph, and let v ∈ V . The i n-degree of v is the number ofedges in E that have v as the endpoint. The out-degree of v is the number of edges in E that havev as the starting point.Example 18.3: Consider the graph in Figure 18.2. The vertex “right sock” has in-degree zerobecause there are no edges coming in, and has out-degree 1 because there is one edge leaving it2Lecture 18: Digraphs 18.1. Directed Graphsright sockunderwearleft sockpantsleft shoeright shoebeltshirtsweaterjacketFigure 18.2: A topological ordering of the graph of clothing dependencies from Figure 18.1.(the one that goes to vertex “right shoe”). The vertex “pants” has in-degree 1 and out-degree 4.The vertex “right shoe” has in-degree 2 and out-degree 0. ⊠Four vertices in the directed acyclic graph of Figure 18.1 have in-degree zero: r ight sock, un-derwear, left sock, and shirt. This observation is a key step towards proving Theorem 18.2.Claim 18.4. Every finite nonempty directed


View Full Document
Loading Unlocking...
Login

Join to view Lecture 18 - Digraphs and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 18 - Digraphs and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?