Processing math: 100%
Lecture Notes: Directed Graphs
Preliminaries
- Name tags
- Sign in
- Quiz 2 reminder
Course Content
Tuesday Review
Question: Give an inductive definition for balanced strings of parentheses using the alphabet Σ={(,),[,]}
Answer:
- Base case: The empty string λ is a BSP.
- Constructor cases:
(C1) If x is any BSP then so is (x)
(C2) If x is any BSP then so is [x]
(C2) If x and y are BSPs, then so is xy, the result of concatenating x and y.
Thursday Review
Review Written Assignment 7.
Motivation
- The next few weeks we will be talking about graphs. Graphs are a core concept in CS, and are used to represent many different things. For example, a Google Maps uses graphs to represent streets.
- Today our focus will be on directed graphs.
- Graphs have come up a few times in the course already, but today you will see a mathematical definition of graphs.
Definition
- Directed graphs can be represented using binary relations.
- Draw: For example:
V={a,b,c,d,e}
A={⟨a,b⟩,⟨b,c⟩,⟨a,c⟩,⟨c,d⟩,⟨c,c⟩,⟨d,b⟩,⟨b,d⟩}
- Draw the vertices, then connect them using the edges.
- Some interesting features:
- c has a self-loop.
- e is not part of any binary relation.
- b and d have edges going in both directions.
- Write: Definition: A directed graph, or digraph, is an ordered pair ⟨V,A⟩ where V is a non-empty set and A is a subset of V×V. The members of V are called vertices and the members of A are called arcs, or edges.
- Ask: According to our definition, can there be more than one arc in the same direction?
- Write: Notation: For convenience, we will write arcs as v→w rather than ⟨v,w⟩.
- It’s possible for a graph to have an infinite number of vertices and edges, but we will work with finite digraphs.
- Ask: What are the vertices and edges in each of these digraphs?
- City streets
- Flights between cities
- Computer networks (mention data diodes)
Movement in Digraphs
- Next, we will introduce some terminology to describe moving through digraphs.
- Write: Definition: A walk in a digraph is a way of proceeding through a sequence of vertices by following arcs.
- Draw: Walks from b to d in the example graph:
- Write: Definition: A walk in a digraph ⟨V,A⟩ is a sequence of vertices v0,…,vn∈V for some n≥0 such that vi→vi+1∈A for each i<n. The length of this walk is n, the number of arcs (one less than the number of vertices).
- Write: Definition: A path is a walk that doesn’t repeat any vertex.
- Ask: Can someone describe a sequence of vertices which forms a path?
- Write: Definition: A circuit is a walk in which the first and last vertices are the same.
- Give an example.
- Write: Definition: A circuit is a cycle if only the first and last vertex is repeated.
- Give an example.
- Write: Definition: A trivial path or cycle has length zero. A nontrivial path or cycle has length greater than zero.
- Write: Definition: A digraph without any nontrivial cycles is acyclic.
- Draw: An acyclic graph.
- Write: Theorem: If there is a walk from one vertex to another, then there is a path from one to the other.
- Write: Informal Proof: Any nontrivial cycle along the way can be left out.
- Suppose there is a walk from v to w: v=v0→…→vn=w
- Suppose the walk includes a cycle: vi→vi+1→…→vj where i<j and vi=vj.
- Then a shorter walk can be formed by removing the cycle: v=v0→…→vi→vj+1→…→vn=w
- By repeatedly removing each cycle, eventually a walk without cycles will be formed: that is, a path.
- Draw: A graph with vertices: v=v0,vi=vj,vi+1,vj−1,vj+1,vn=w
- For example, the walk b→d→b→d can be simplified to b→d by removing the cycle.
- Write: Theorem: For vertices v,w there is a path from v to w if and only if there is a walk from v to w.
- Write: Definition: Vertex w is reachable from vertex v if there is a path from v to w.
- Write: Definition: The distance from vertex v to vertex w in a digraph G, is the length of the shortest path from v to w, or ∞ if there is no such path, and is denoted: dG(v,w)
- Ask: What are these distances?
- dG(a,b)=1
- dG(a,c)=1
- dG(a,d)=2
- dG(a,e)=∞
- dG(a,a)=0
Connectivity
- Write: Definition: A digraph in which every vertex is reachable from every other vertex is strongly connected.
- Ask: Given this definition, is our graph strongly connected? Erase e. What if we forget about e?
- Connectivity is an important concept for many real-world graphs.
- Ask: What would it mean if a graph of roads was not strongly connected?
Subgraphs
- Write: Definition: If G=⟨V,A⟩ is a digraph and V′⊆V and A′⊆A and every arc in A′ is between vertices that are in V′, then ⟨V′,A′⟩ is said to be a subgraph of G.
- Ask: Are these subgraphs of G?
- ⟨{a,b,c},{⟨a,b⟩,⟨b,c⟩,⟨a,c⟩}⟩
- ⟨{a,b},A⟩
- ⟨{a,b},{⟨a,b⟩,⟨b,c⟩,⟨a,c⟩}⟩
- Write: Definition: If V′⊆V is any subset of the vertices of G, the subgraph induced by V′ includes all the arcs in A with both endpoints in V′. That is:
⟨V′,{v→w∈A:v,w∈V′}⟩
- Ask: What are the subgraphs induced by these vertex sets? Are they strongly connected?
Directed Acyclic Graphs (DAGs)
- Recall the earlier definition: A digraph without any nontrivial cycles is acyclic.
- Directed acyclic graphs are common in Computer Science and are often abbreviated as “DAGs.”
- DAGs can represent constraints on ordering, without fully specifying the ordering.
- For example, let’s look at the Computer Science introductory sequence:
- Draw:

- Ask: What are some possible orders in which you could take these courses? An example of an invalid ordering?
- Ask: What would it mean if there was a cycle in this graph? Why would that be a problem?
- Write: Definition: The out-degree of a vertex v is the number of arcs leaving it. That is: |{w:v→w∈A}|
- Write: Definition: The in-degree of a vertex v is the number of arcs entering it. That is: |{w:w→v∈A}|
- Write: Theorem: A finite DAG has at least one vertex of out-degree 0 and at least one vertex of in-degree 0.
- Proof: Let G=⟨V,A⟩ be a finite DAG.
- We’ll prove by contradiction that G has a vertex of out-degree 0. Suppose to the contrary that G has no vertex of out-degree 0. Pick any vertex v0. Since v0 has positive out-degree, there is an arc v0→v1 for some vertex v1. By the same reasoning, v1 has positive out-degree, and there is an arc v1→v2 for some vertex v2. This reasoning applies to every vertex, since every vertex has positive out-degree.
- Because V is finite, some vertex will be repeated, creating a cycle. This contradicts the assumption that the digraph was acyclic.
- A similar argument would prove that G has a vertex of in-degree 0.
- If G had no vertex of in-degree 0, we could start from any vertex v0 and follow arcs backwards until a vertex was repeated, forming a cycle.
- Write: Definition: In a DAG, a vertex of in-degree 0 is called a source and a vertex of out-degree 0 is called a sink.
- Ask: In our CS courses graph, which vertex is a source? Which vertices are sinks?
Tournament Graphs
- Write: Definition: A tournament graph is a digraph in which every pair of distinct vertices are connected by an arc in one direction or the other, but not both.
- A tournament graph represents the outcome of every team (or player) playing every other team (or player) exactly once.
- Sometimes there is a clear champion, and sometimes the result is inconclusive.
- Draw: Consider these two graphs:

- A vertex represents a team. An arc represents the team at the tail of the arc defeating the team at the head of the arc.
- Ask: Does the first graph show a clear champion? Does the second graph?
- In a tournament graph, the number of arcs depends on the number of vertices. In particular, a tournament graph with n vertices will contain n(n−1)2 vertices.
- With 5 teams, 10 games would need to be played. With 25 teams, 300 games would need to be played!
- So it wouldn’t be feasible to structure a tournament like this if there was many teams.
- Write: Definition: A linear order, denoted by ⪯, is a binary relation on a finite set S with the property that the elements of S can be listed S={s0,…,sn} in such a way that si⪯sj if and only if i≤j.
- For example, if S is the set of Clark students, then we could define a linear order si⪯sj to mean that either student si has a last name that appears before sj alphabetically, or they have the same last name.
- Write: Definition: A strict linear order, denoted by ≺, is an ordering such that si≺sj if and only if i<j
- A set is strictly linearly ordered by a binary relation if there is one and only one way to list it so that earlier elements in the list always precede later elements in the list, according to the binary relation.
- For the set of Clark students, if students have the same last name, then multiple linear orderings are possible. So ordering alphabetically by last name doesn’t establish a strict linear order.
- Ask: How could we establish a strict linear order of Clark students? Student ID number. Email address.
- Write: Theorem: A tournament digraph represents a strict linear order if and only if it is a DAG.
- Proof: Let G=⟨V,A⟩ be a tournament digraph.
- First, we will prove that if G represents a strict linear order, then G is acyclic. If G represents the strict linear order v0≺v1≺…≺vn, then every arc goes from a vertex vi to a vertex vj where i<j. Then the digraph is acyclic, since any cycle would have to include at least one arc vj→vi where j>i.
- Next, we will prove that if G is a DAG, then it represents a strict linear order. We will perform induction on the number of vertices.
- Base Case: If G has one vertex, it is trivially a strict linear order.
- Induction Step: If G has more than one vertex, by our DAG theorem we know at least one vertex has in-degree 0, which we call v0. Since G is a tournament graph, G must contain arcs v0→vi for i≠0. Consider the subgraph induced by V−{v0}. This induced subgraph is also a DAG, since all its arcs are arcs of G, which contains no cycles. Also, it is a tournament graph, since G is a tournament graph and the subgraph includes all the arcs of G except those involving v0. By the I.H., the induced subgraph represents a strict linear order, say v1≺v2≺…≺vn. As v0 has in-degree 0, v0≺vi for i≠0, so putting v0 first yields the strict linear order for all of V. That is: v0≺v1≺v2≺…≺vn.
- By repeatedly removing the vertex with in-degree 0, we can find the strict linear order of a tournament subgraph. (Demonstrate with Figure 13.7).
- Strict linear order: H≺Y≺P≺D
Infinite Digraphs
The textbook concludes by discussing an infinite DAG formed from the natural numbers by the predecessor relation. We will discuss this next week.