Processing math: 94%
Lecture Notes: Digraphs and Relations
Preliminaries
Course Content
Tuesday Review
Question: Draw digraphs which are:
- Strongly connected and acyclic.
- Strong connected and not acyclic.
- Not strongly connected and acyclic.
- Not strongly connected and not acyclic.
Thursday Review
Question: Draw a digraph representing the relation mod3(m,n) if and only if m%3=n.
Is this graph: Reflexive? Symmetric? Transitive?
Motivation
- Last week, we focused on finite digraphs.
- This week, you will see examples of infinite digraphs.
- You will see that relations and functions can be interpreted as graphs.
- We will also discuss more graph properties.
Infinite Digraphs
- Last week, we focused on finite digraphs: a finite number of vertices and arcs.
- This week, we will see some examples of infinite digraphs.
- Relations or functions can be interpreted as graphs.
- Consider the predecessor relation: f(x)=x+1 for f:N→N
- The relation forms arcs: x→f(x)
- If we draw the graph: 0→1→2→3→…
- Ask: Is this graph a DAG? What vertex is the source? Is there a sink?
- Remember that all functions are relations, so we can write the predecessor relation using relation notation.
- Write: m is the predecessor of n, pred(m,n) if and only if n=m+1.
- Let’s consider a different binary relation, and interpret it as a graph.
- Write: m is less than n, lt(m,n) if and only if m<n.
- Draw:

- In the full digraph of the less-than relation, every vertex would have infinite out-degree (since for any number m, there are infinitely many n greater than m) and finite in-degree (because n is greater than exactly n natural numbers: 0,…,n−1).
- Last week, we talked about defining a strict linear order on a set using a binary relation.
- Write: Definition: A strict 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.
- Let’s think about whether each of these binary relations establishes a strict linear order on the set of natural numbers.
- For pred(m,n) and lt(m,n):
- m=0,n=1? Yes. Yes.
- m=1,n=2? Yes. Yes.
- m=0,n=2? No. Yes.
- m=1,n=1? No. No.
- The predecessor relation doesn’t establish a strict linear order. The less than relation does.
- Later in the week, we will explain how strict linear order can be defined in terms of graph properties.
- Today, we will see a connection between these two relations.
Transitive Relations
- Write: Definition: A binary relation R⊆S×S is transitive if for any elements x,y,z∈S, if R(x,y) and R(y,z) both hold, then R(x,z) also holds.
- The less-than relation on natural numbers is transitive, since if x<y and y<z then x<z.
- Draw: In a graph of a transitive relation, you will see that:

- All linear orders are transitive, but many relations that are not linear orders are also transitive.
- “For example, consider the relations child and descendant between people, where child(x, y) is true if and only if x is a child of y, and descendant(x, y) is true if and only if x is a descendant of y.
- So descendant(x, y) holds if child(x, y) holds.
- The relation descendant(x, y) also holds if x is a grandchild of y; that is, there is a z such that child(x, z) and child(z, y).
In general, descendant is transitive, because a descendant of a descendant of a person is a descendant of that person.”
- Draw: A family tree to illustrate.
- In any directed graph G, reachability is a transitive relation, since if there is a walk from u to v and a walk from v to w, then there is a walk from us to w: just connect the end fo the first walk to the beginning of the second.
- Write: Definition: The transitive closure of a binary relation R is the smallest relation that contains R and is transitive. It is denoted R+.
- Credit: Wikipedia. I think it does a better job explaining transitive closure than the textbook.
- For example, consider the flight(x,y) relation, showing it is possible to fly from airport x to airport y.
- Draw: ORH → JFK, ORH → LGA, JFK → BOS, BOS → DUB
- Ask: Has anyone taken any fights from Boston or NYC recently? Add them to the graph.
- The transitive closure of the flight relation, flight+(x,y), shows whether it is possible to fly from airport x to y.
- Draw: Additional arrows to show the transitive closure.
- Let’s figure out the transitive closures of the relations we talk about earlier.
- child+=descendant
- pred+=lt
- Draw: Vertices: a, b. Edges: a → b, b → a.
- Ask: Is this graph transitive?
- Answer: No. To be transitive, it must also include a → a and b → b. Refer to the definition. What if x and z refer to the same vertex? Then you need self-loops.
Reflexive Relations
- Write: Definition: A binary relation R is reflexive if R(x,x) holds for every x∈S.
- Ask: Are these relations reflexive?
- Write: Definition: A binary relation R is irreflexive if it is never the case that R(x,x) for any x∈S.
- Ask: Are these relations reflexive?
- Write: Definition: The reflexive closure of a binary relation R adds to R any ordered pairs ⟨x,x⟩ that are not already in R:
R∪{⟨x,x⟩:x∈S}
- This means every vertex will have a self-loop.
- Write: Definition: The reflexive transitive closure of R is denoted R∗, and is formed by taking the reflexive closure of the transitive closure.
- For example: pred∗ is ≤
- Thinking about digraph representations: there is an arc x→y in R∗ if and only if there is a path (trivial or nontrivial) from x to y in R.
- The reflexive, transitive closure of a digraph is also referred to as its reachability relation.
Computer State as a Graph
- Consider a graph of the states of a computer.
- For a general-purpose computer, this graph would be enormous, since all possible states of all memory cells are represented as different vertices.
- Arcs represent changing from one state to another as a result of computation.
- Draw: A vertex for freshly powered-on. A vertex for crashed. Vertices in between.
- An important question is whether running a program will crash the computer, run forever, or give a valid output.
- You will explore this concept in CSCI 180: Automata Theory
Symmetric Relations
- Write: Definition: A binary relation R⊆S×S is symmetric if R(y,x) holds whenever R(x,y) holds.
- In terms of the digraph representation, a symmetric relation has an arc x←y whenever it has an arc x→y.
- For notational convenience, this can be depicted as x↔y.
- A graph containing two-way roads is symmetric. A graph containing at least one one-way road is not symmetric.
- Write: Definition: A relation is asymmetric if it is never the case that both x→y and y→x for any elements x and y.
- Ask: Can a reflexive relation be asymmetric? No, because self-loops would violate the asymmetry condition. Asymmetric relations are irreflexive.
- Write: Definition: A relation is antisymmetric if x→y and y→x both hold only if x=y.
- Ask: Can a reflexive relation be antisymmetric? Yes. For example, ≤ on integers.
Equivalence Relations
- Transitivity, reflexivity, and symmetry are independent of each other.
- Write: Definition: A binary relation that is symmetric, reflexive, and transitive is called an equivalence relation.
- For example, assume every person has only one place of birth (POB). The binary relation between people with the same POB is an equivalence relation:
- It is symmetric: if your POB is the same as mine then mine is the same as yours
- It is reflexive: since I was born in the same place as myself
- It is transitive: if x and y share a POB and y and z share a POB then x and z also have the same POB.
- An equivalence relation can be used to split a set into disjoint subsets.
- Write: Definition: A collection of disjoint subsets of set S is called a partition of S. Each set in the partition is called a block. Symbolically, T⊆P(S) is a partition of S if and only if:
- Each block is nonempty. That is, if X∈T, then X≠∅.
- The blocks are disjoint. That is, if X1,X2∈T, and X1≠X2, then X1∩X2=∅.
- The blocks exhaust S. That is, if T=X1,X2,…,Xn then S=X1∪X2∪…∪Xn.
- Recall that the binary relation between people with the same POB is an equivalence relation.
- Intuitively, you can use this binary relation to form a partition of all people into blocks within which people share the same POB.
- We will formalize this with a theorem.
- Write: Theorem: Let ↔ be any equivalence relation on a set S. Then the equivalence classes of ↔ are a partition of S. Conversely, any partition of S, say T, yields an equivalence relation ↔ on S in which all elements in the same block of T are equivalent to each other under ↔.
- Proof, part 1: If ↔ is an equivalence relation on S, then
T={{y:y↔x}:x∈S}
is a partition of S, since every element of S is in one and only one block in T.
- Proof, part 2: If T is a partition of S, then the relation ↔ such that x↔y if and only if x and y belong to the same block of T is reflexive, symmetric, and transitive, and is therefore an equivalence relation:
- It is symmetric: x and y are in the same block, y and x are in the same block
- It is reflexive: since x is in the same block as x
- It is transitive: if x and y share a block and y and z share a block then x and z also share the same block.
- Mention implementing
__eq__
in Python
Strongly Connected Components
- Let’s review a definition from last week:
- Write: Definition: A digraph in which every vertex is reachable from every other vertex is strongly connected.
- Reachability is a transitive relation, but is not necessarily symmetric.
- Draw: Demonstrate using this graph:

- However, mutual reachability is transitive and symmetric.
- Demonstrate using the graph.
- Furthermore, each vertex is trivially reachable from itself, so mutual reachability is reflexive.
- Ask: Since mutual reachability is symmetric, reflexive, and transitive, what does that mean about the relation? It is an equivalence relation.
- So we can partition a digraph using the mutual reachability relation.
- Draw: Circle the blocks in the graph.
- Write: Definition: The subgraphs induced by the blocks of the mutual reachability relation are called the strongly connected components of the digraph, or simply strong components. Each strongly connected component is a strongly connected digraph, and no two vertices in different strong components are mutually reachable.
- For time, skip Theorem 14.3.
Partial Order Relations
- Recall from last week:
- 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.
- We will see an alternate definition based on graph properties.
- Write: Definition: A partial order is a reflexive, antisymmetric, transitive binary relation.
- For example:
- ≤ is a partial order on natural numbers
- ⊆ is a partial order on P(N)
- Draw: ≤ and ⊆ as graphs.
- Write: Definition: A linear order is a partial order such that any two distinct elements are related one way or the other.
- All linear orders are partial orders. Not every partial order is a linear order.
- ≤ is a partial order and a linear order
- ⊆ is a partial order, but not a linear order. For example, 0⊈ and {1} \not\subseteq {0} .
- Write: Definition: A strict partial order is an irreflexive, antisymmetric, transitive binary relation. No self-loops.
- For example:
- < is a strict partial order on natural numbers
- \subsetneq is a strict partial order on \mathcal{P}(\mathbb{N})
- Draw: < and \subsetneq as graphs.
- Write: Definition: A strict linear order is a strict partial order such that any two distinct elements are related one way or the other.
- The graph of any strict partial order is a DAG.
- Any partial order is the reflexive, transitive closure of a DAG.
- Let’s turn the CS prerequisite DAG into a partial order.
- Draw:

- Add self-loops
- Add arcs to form transitive closure.
- Ask: Is this graph a linear order? No. For example, there isn’t an arc between 121 and 122.
- Write: Definition: In a partial order, a minimal element is one that is not greater than any other element.
- Ask: What is the minimal element in this graph?
- Ask: Is it possible for a partial order to have multiple minimal elements? Erase 120. Then 121 and 122 are both minimal elements.
- Mention implementing
__lt__
in Python