Digraphs Discrete Math – Section 13.5 I. Intro to Digraphs We now turn our focus to directed graphs, or graphs where all edges have directions associated with them. Because we mathematicians are lazy, we usually just call these digraphs. Digraph terminology: Let D be a digraph. Then… The edges of D are called arcs. The vertex where an arc starts is called its initial point. The vertex where an arc ends is called its terminal point. The graph formed by disregarding the directions on the edges of D is called the underlying graph of D. Example 1 Consider the digraph shown here. a. Give the initial and terminal points of each arc. arc b. Draw the underlying graph. Example 2 Draw the digraph with following specifications: arc e1 e2 e3 e4 e5 e6 e7 initial point v1 v3 v3 v4 v2 v4 v3 initial point terminal point v2 v2 v4 v1 v4 v2 v3 terminal point II. Indegree and Outdegree We have the notion of degree for general graphs. When we have directed graphs, it is often useful to break up the degree based on whether arcs are coming into a node or out of a node. We define two new quantities: Definition Let v be a vertex in directed graph D. Then Define the indegree of v to be the number of arcs whose terminal point is v. [Notation: indeg(v)] Define the outdegree of v to be the number of arcs whose initial point is v. [Notation: outdeg(v)] Example 3 Consider the digraph shown. Find the indegree and outdegree of each vertex. Problem Return to example 2. Find the indegree and outdegree for each vertex of the graph from Example 2. III. Walks and Connectedness in Digraphs We can also extend our definitions from the section on walks to digraphs. We begin by looking at directed paths. Definition Let D be a digraph. A directed path in D is a sequence of vertices and edges s.t. the terminal point of one arc is the initial point of the next. Definition Let D be a digraph and let v, w V(D). If there exists a directed path from v to w in D, then we say w is reachable from v. Example 4 Consider the digraph shown to the right. a. Find three distinct directed paths from v1 to v5. b. Is v1 reachable from v4? Is v1 reachable from v5? c. Is v3 reachable from v1? Definition Let D be a digraph. If every vertex of D is reachable from any other vertex in D, then we call D strongly connected. If the underlying graph of D is connected, then we say D is weakly connected. Note that we do not call a graph both strongly connected and weakly connected. Strongly connected "trumps" weakly connected. Example 5 Which of the two digraphs shown here is strongly connected and which is weakly connected? Why? IV. More Spanning Trees: Depth-First Search In the last section we looked at Prim's and Kruskal's algorithms for growing minimum spanning trees for graphs. There, our goal was to find a spanning tree for any given graph such that the spanning tree had minimum weight. Certainly, there could be other criteria besides just weight for choosing a spanning tree. In Kruskal's Algorithm, we grew the spanning tree one edge at a time, in order of increasing weights. In Prim's algorithm, we picked one starting vertex and grew the tree from the starting vertex, always making the best choice of edge. Note that both Kruskal and Prim are what we call greedy algorithms, in the sense that, at each step, they always select the choice that looks best at the moment. It shall be noted that while most greedy strategies for solving problems do produce the globally optimal solution, not all greedy algorithms do. Now we look at spanning trees with different priorities. The depth-first search produces a tree in an order that, like its name implies, goes deeper into the tree before it goes broader into the tree. Here is the algorithm: Algorithm: Depth-First Search Input: graph G, starting vertex v Procedure: 1. Initialize a counter n at 0. Initialize a spanning tree T with vertex v only. 2. Mark v as node 0 and increment n. 3. Follow an edge from v to a new vertex. Number the new vertex n and increment n. Add it to the spanning tree T. Continue going one more step away from v, adding each vertex encountered to T, numbering each vertex n, and incrementing n until is no longer possible to go any further away from v. 4. Backtrack to the vertex u we were last able to add successfully and from which we could find another path to extend the tree. Repeat step 3 using u in place of v. 5. Repeat step 4 until T is a spanning tree, i.e. contains all vertices of G. Output: depth-first spanning tree for G with a depth-first numbering telling the order in which vertices were added Note that depth-first search is in contrast to breadth-first search, where we add as many nodes as we can in one level before we go deeper into the tree. Example Perform a depth-first search on the graph shown below. V. Orientable Graphs Question: Suppose we have a graph that represents a network of streets in a town where vertices represent intersection and edges represent streets. Can we make all the streets one-way streets and still have a strongly connected graph? To answer this question, we consider the orientation of a graph. Definition Let G be a graph. If every edge in G can be given a direction such that the result is a strongly connected digraph, then G is said to be orientable. Definition Suppose G is a connected graph. An edge of G whose removal results in a disconnected graph is called a bridge. Then we assert the following theorem: Theorem A graph G is orientable iff it is connected and has no bridges. We have an algorithm for producing an orientation for an orientable graph: Algorithm for Orienting a Graph Input: orientable graph G Procedure: 1. Perform a depth-first search on G. Obtain a spanning tree T. 2. Assign directions to the edges of T as follows: Each edge is directed from vertices of lower to higher depth-first number. 3. Assign directions to all edges of G that are not in T as follows: Each edge is directed from vertices of higher to lower depth-first number. Output: an orientation for G Problem Determine whether the graph shown below is orientable. If it is, orient the graph so that it is strongly connected. Homework: Section 13.5: #1-17 odd