Processing math: 4%
Lecture Notes: Undirected Graphs
Preliminaries
- Name tags
- Sign in
- Announce quiz
Course Content
Tuesday Review
- Draw a digraph with 6 vertices and two connected components.
- Partition the vertices in your digraph using the mutual reachability relation.
Thursday Review
Defer review of Written Assignment 8 to next class.
Motivation
- We have been talking about directed graphs for the past two weeks.
- This week, we will talk about undirected graphs.
- Basically, an undirected graph has vertices connected by lines instead of arrows.
- Draw: An undirected graph with four vertices and some edges.
- Whether to represent something using directed or undirected graphs depends on whether the connections between vertices have a meaningful direction.
Definition
- Write: Definition: An undirected graph, or graph, is a collection of vertices and edges connecting vertices. Formally, graph G=⟨V,E⟩, where V is a set of vertices and E is a set of edges.
- Write: Definition: An edge is a two element subset of V. For convenience, we write edges as x–y rather than {x,y}. x and y are endpoints of edge x–y, which joins x and y. We also say that x and y are incident on the edge x–y.
- Draw: Let’s see another graph:
V={1,2,3,4,5,6,7,8,9}
E = \{ 1–4, 2–4, 4–5, 2–5, 5–3, 5–6, 3–6, 7–8 \}
- Ask: Based on the mathematical definition of graphs, are these possible?
- 1-4 and 4–1 (multiple edges). These refer to the same edge.
- 2–2 (self-loops). This would be a one element subset of V.
Walks, Paths, Circuits, Cycles
- You will see that the definitions of walk, path, circuit, and cycle for graphs are very similar to the definitions for digraphs.
- Write: Definition: A walk in a graph is a series of one or more vertices in which successive vertices are joined by an edge. The length of a walk is the number of edges.
- Example walk: 1–4–2–5–4–1
- Write: Definition: A path is a walk that does not repeat any edge.
- Write: Definition: A circuit is a path that ends at its beginning.
- Example circuit: 2–4–5–3–6–5–2
- Write: Definition: A cycle is a circuit that repeats no vertex, except that its first and last vertices are the same. A single vertex is not a cycle.
- Ask: Are each of these: Walks? Paths? Circuits? Cycles?
- Let’s review the Well-Ordering Principle, which we will use in a proof.
- Write: Well-Ordering Principle: Any nonempty set of nonnegative integers has a smallest element.
- Write: Theorem: Any circuit includes a cycle.
- Before we prove it, let’s see an example using circuit: 2–4–5–3–6–5–2
- Write: Proof: Suppose C = v_0–v_1–\ldots–v_n = v_0 is a circuit of length n. We find a cycle within this circuit by finding a subsequence of these vertices comprising a path of length at least 3, with no duplicate vertices except that the first and last vertices are the same.
- Let 0 \leq i < j \leq n be such that v_i = v_j and j - i is minimal: that is, there are no k and l, 0 \leq k < l \leq n, such that v_k = v_l and l - k < j - i. We can find such i and j by the Well-Ordering Principle, since the set of values of j - i such that i < j and v_i = v_j has a smallest element.
- We know j - i \geq 3 :
- j - i = 1 would require an edge from v_i to itself (no self-loops in graphs).
- j - i = 2 would mean returning to v_i from v_j using the same edge (not a path).
- Thus, v_i–v_{i+1}–\ldots–v_j = v_i is a cycle: it is a path of length at length at least 3 that ends at its beginning, and if there were a pair of duplicates among the vertices v_{i+1}, \ldots, v_j the difference of their indices would be less than j - i, contradicting the minimality of j - i.
Connectedness
- Write: Definition: Two vertices are connected if there is a path between them. Every vertex is connected to itself (by a path of length zero). Connectedness is an equivalence relation on vertices: the equivalence classes are called the connected components of the graph.
- Ask: What are the connected components of this graph?
- Write: Definition: A graph is connected if it has only one connected component. Otherwise, it is disconnected.
- So this graph is disconnected.
Underlying Graph
- Textbook makes connections between digraphs and graphs. Omitting these for time.
Euler’s Theorem
- Write: Definition: The degree of a vertex is the number of edges incident on it.
- Ask: What is the degree of each of the vertices in this graph?
- Write: Definition: Suppose G = \langle V, E \rangle is a graph, v \in V and e is a set of two vertices in V .
- G - v is the result of removing v and any edges incident on v .
- G - e is the result of removing e but leaving its endpoints.
- G + e is the result of adding e to E .
- Write: Definition: Eulerian circuit: A walk that visits each edge exactly once, starting and ending at the same vertex.
- Motivated by the Seven Bridges of Königsberg: can you walk through the city so you cross each bridge once and only once?
- Each land mass is a vertex, each bridge is an edge:

- Write: Euler’s Theorem: A connected graph has an Eulerian circuit if and only if every vertex has even degree.
- Draw: G:

- Notice that the Seven Bridges of Königsberg graph has double-edges, which aren’t allowed in the simple graphs we have discussed so far. Our proof will assume simple graphs, but the theorem also holds for multigraphs.
- Write: Proof: Suppose that a connected graph has an Eulerian circuit. At every vertex, the number of edges by which the circuit enters the vertex is equal to the number of edges by which the circuit leaves the vertex, since a circuit returns to its start vertex; this accounts for every edge in the graph, since each edge appears exactly once in an Eulerian circuit. So the total number of edges incident on each vertex is even.
- Suppose that G is a connected graph and each vertex has even degree. We prove that G has an Eulerian circuit by induction on the number of edges of G.
- P(n) is the predicate: “If G is a connected graph with n edges, and each vertex has even degree, then G has an Eulerian circuit.”
- Base case: No graph with fewer than 3 edges can have an Eulerian circuit. If G has 3 edges, it is a triangle and therefore an Eulerian circuit.
- Induction hypothesis: For some fixed n \geq 3, assume P(m) holds for all m such that 3 \leq m \leq n .
- Induction step: Suppose G is a connected graph with vertices of even degree, and it has n + 1 edges.
- We can always construct a circuit: pick any vertex and wander around the graph, following edges but not reusing any edge that has already been traversed, until returning to the original vertex. It is possible to leave any vertex other than the original vertex via an unused edge: its counts of unused incident edges was even before it was reached, became odd when it was reached, and became even again upon leaving the vertex. We will eventually reach the original vertex again: it is possible to leave any other vertex that is reached, so the walk is only forced to end at the original vertex.
- Thus, a circuit exists, but it might not include every edge. Let’s call the circuit C = c_0–c_1–\ldots–c_l .
- Draw: C (see above)
- Removing all the edges of C breaks the graph into a set S of connected subgraphs. Each of these graphs has fewer edges than G. Every vertex in each graph in S has even degree, since each vertex lost an even number of incident edges when C was removed from G. By induction, each H \in S has an Eulerian circuit C_H. It remains only to connect C and C_H to create an Eulerian circuit of G.
- Draw: H:

- Each H \in S shares a vertex with C since G was a connected graph. Let’s say that v_H is a vertex that H shares with C. Construct an Eulerian circuit of G by starting at c_0 and following the edges of C until c_l = c_0 is reached, taking a detour at each vertex c_i to follow the Eulerian circuit of any graph H \in S such that v_H = c_i.
- Suppose v_H = c_0. Then the Eulerian circuit in our example would be:
c_0–c_2–c_4–c_1–c_3–c_0 - c_1–c_2–c_3–c_4–c_0
- Ask: Will this graph have an Eulerian circuit? No: there are vertices with odd degree.

Isomorphism
- Write: Definition: Function f : A \rightarrow B is a bijection if and only if, for every element y \in B , there is one and only one element x \in A such that f(x) = y .
- Write: Definition: Two graphs are isomorphic if there is a bijection between their vertices that preserves their edges. An isomorphism between two graphs G = \langle V, E \rangle and G’ = \langle V’, E’ \rangle is a bijection f : V \rightarrow V’ such that x–y \in E if and only if f(x)–f(y) \in E’ .
- Informally, isomorphic graphs are the same “up to renaming vertices.”
- Ask: Are these graphs isomorphic? Yes: 1 \leftrightarrow A, 2 \leftrightarrow D, 3 \leftrightarrow C, 4 \leftrightarrow B, 5 \leftrightarrow E . No. No.



- Write: Algorithm:
- If different number of vertices or edges, then not isomorphic
- If different number of vertices of degree 0, 1, 2, etc., then not isomorphic
- Otherwise, use brute force to try matching vertices between the graphs
- Usually we care about graph properties which don’t depend on how the graph is drawn. These properties are said to hold “up to isomorphism.”
- Write: Definition: A graph is planar if it is possible to draw it in the plane (e.g., on paper) in such a way that no two edges cross.
- If a graph is planar, then any graph isomorphic to it is planar, too.
- The first pair of graphs we considered is planar.
- This property is useful in circuit board design: single-layer circuitboards are easier to produce, so ideally circuit designs are planar.
Distance and Diameter
- Write: Definition: The distance between two vertices is the length of the shortest path between them.
- Ask: What are the distances between: 1 and 2? 1 and 3?
- Write: Definition: The diameter of a graph is the greatest distance between any two vertices.
- Ask: What is the diameter of each graph?
- Write: Definition: The graph with n vertices and all possible edges is called the complete graph on n vertices, and is denoted by K_n.
- Draw: K_1, K_2, K_3, K_4, K_5
- K_n has \frac{n(n-1)}{2} edges.
- Ask: What is the diameter of a complete graph?
- If time, discuss social network example. Friends, friends of friends.
Trees
- Write: Definition: A tree is a connected acyclic graph. A forest is an acyclic graph: a graph in which the connected components are trees.
- The minimal graph connecting a set of vertices is a tree.
- Skipping proofs of tree theorems for time.
- Write: Theorem: A tree with n vertices has n-1 edges.
- Write: Theorem: Removing an edge from a tree without removing any vertices disconnects it. Adding an edge to a tree without adding any vertices creates a cycle.
- Write: Theorem: Between any two vertices in a tree, there is one and only one path.
Weighted Edges
- Write: Definition: A numerical value associated with an edge is called its weight. We can use a function w : E \rightarrow D to indicate the weight of edge e .
- Draw:

- Ask: What are: w(A–B) ? w(B–C) ? w(A–C) ?
- Weights can indicate distances on a map, capacities of network connections, and many other things.
Minimum Spanning Trees (MSTs)
- Imagine that you are an internet service provider (ISP) wiring a new neighborhood. You need to connect all houses to the ISP, and you want to minimize the cost of the cabling installation. Vertices: houses. Edges: potential cabling routes. Weight: cost of cabling.
- Our goal is to find a “minimum spanning tree” of the graph.
- First, some definitions.
- Write: Definition: For any graph G = \langle V, E \rangle , a subgraph of G is any graph H = \langle V’, E’ \rangle such that V’ \subseteq V and E’ \subseteq E and all endpoints in E’ are in V’. We write H \subseteq G when H is a subgraph of G.
- Write: Definition: A spanning tree of G is a subgraph of G that is a tree and includes every vertex of G.
- Write: Definition: If the edges of G are labeled with numbers, then a minimum-weight spanning tree (MST) is a spanning tree T \subseteq G such that the sum of the labels of the edges is minimal. The weight of tree T = \langle V_T, E_T \rangle is defined as the sum:
w(T) = \sum_{e \in E_T} w(e)
- Ask: What are the spanning trees of the weighted graph? What is the minimum spanning tree?
- There can be multiple minimum spanning trees. For example, if all the edges have the same weight, then any spanning tree is a minimum spanning tree.
Kruskal’s Algorithm
- We can efficiently find a minimum spanning tree using Kruskal’s Algorithm
- Write: Kruskal’s Algorithm:
- Starting from a graph with no edges, add edges one at a time in order of increasing weight, skipping any edge that would form a cycle.
- The MST is complete after n - 1 edges have been added.
- Tree are gradually merged together until all vertices are connected.
- Draw: Example of Kruskal’s Algorithm:

- TODO Include proof if time.