Graph Theory Basics
Graph theory basics start with three ideas. A graph is a set of vertices (dots) joined by edges (lines). The degree of a vertex is the number of edges that touch it. The handshaking lemma says the degrees of all the vertices always add up to twice the number of edges.
Before this lesson: Sets and Subsets, Properties of Relations and Direct Proof
The idea
Many problems are about things and the connections between them: friends on a social network, cities and the roads between them, computers on a network. A graph keeps only that structure. Each thing becomes a vertex, and each connection becomes an edge.
Where the dots sit and how the lines bend do not matter. Two drawings show the same graph when they have the same vertices and the same pairs joined by edges. Edges can even cross in a drawing without meeting; only the marked dots are vertices.
Graph theory basics: definitions
A graph G = (V, E) has a set V of vertices and a set E of edges. Each edge joins two vertices, called its endpoints. We write an edge as a pair such as {A, B}, or AB for short.
| Term | Meaning | In the graph above |
|---|---|---|
| Adjacent vertices | two vertices joined by an edge; write u \sim v | A and B are adjacent; A and D are not |
| Incident | an edge is incident to its two endpoints | edge BD is incident to B and D |
| Loop | an edge that joins a vertex to itself | none |
| Multiple edges | two or more edges joining the same pair | none |
| Simple graph | a graph with no loops and no multiple edges | yes, it is simple |
| Degree \deg(v) | the number of edges incident to v, with a loop counted twice | \deg(B) = 3 |
| Isolated and pendant vertices | a vertex of degree 0, and a vertex of degree 1 | E is a pendant vertex |
| Path | distinct vertices, each joined to the next by an edge; its length is its number of edges | A, B, D, E has length 3 |
| Cycle | a path with at least 3 vertices plus an edge from its last vertex back to its first | A, B, C, A |
| Connected graph | a path joins every pair of vertices | yes, it is connected |
A graph that allows multiple edges is a multigraph. Unless a problem says otherwise, “graph” in this course means a simple graph.
The handshaking lemma
Think of each edge as a handshake between its two endpoints. Adding up the degrees counts every handshake once from each side, so every edge is counted exactly twice.
\sum_{v \in V} \deg(v) = 2|E|Proof. Count the edge ends. Each edge has 2 ends, so there are 2|E| ends in all. Each vertex v holds exactly \deg(v) of those ends (a loop puts both of its ends at the same vertex, which is why it counts twice). Counting the same ends by vertex gives the degree sum, so the two counts are equal.
Corollary. Every graph has an even number of vertices of odd degree. Here is a direct proof.
\sum_{\text{even}} \deg(v) + \sum_{\text{odd}} \deg(v) = 2|E|Split the degree sum into even-degree and odd-degree vertices.
\sum_{\text{odd}} \deg(v) = 2|E| - \sum_{\text{even}} \deg(v)Subtract the even part from both sides.
\sum_{\text{odd}} \deg(v) \text{ is even}An even number minus a sum of even numbers is even.
\#\{v : \deg(v) \text{ odd}\} \text{ is even}A sum of an odd count of odd numbers would be odd, so the count must be even.
Complete graphs
The complete graph K_n has n vertices and an edge between every pair. Each vertex has degree n − 1, so the degree sum is n(n − 1), and the handshaking lemma gives the edge count.
|E(K_n)| = \dfrac{n(n-1)}{2}Graph theory examples
Example 1: Degrees and the handshaking lemma
Find the degree of each vertex in the five-vertex graph above, and check the handshaking lemma.
\deg(A) = 2
A touches edges AB and AC.
\deg(B) = 3
B touches AB, BC and BD.
\deg(C) = 3
C touches AC, BC and CD.
\deg(D) = 3
D touches BD, CD and DE.
\deg(E) = 1
E touches only DE, so E is a pendant vertex.
2 + 3 + 3 + 3 + 1 = 12
Add the degrees.
2 \cdot 6 = 12
Twice the number of edges gives the same total.
Answer: the degrees are 2, 3, 3, 3 and 1, and their sum 12 equals 2 · 6. The four vertices of odd degree (B, C, D and E) form an even count, as the corollary says.
Example 2: Counting edges from degrees
A graph has 10 vertices, and every vertex has degree 3. How many edges does it have? Could a graph have 9 vertices that all have degree 3?
10 \cdot 3 = 30
Add the degrees: 10 vertices of degree 3.
2|E| = 30
Apply the handshaking lemma.
|E| = 15
Divide both sides by 2.
9 \cdot 3 = 27
With 9 vertices of degree 3, the degree sum would be 27.
2|E| = 27
The handshaking lemma would need this.
|E| = 13.5
Divide both sides by 2: not a whole number of edges.
Answer: the first graph has 15 edges. No graph has 9 vertices of degree 3, because its degree sum would be odd.
Example 3: An even sum is not enough
Is there a simple graph whose four vertices have degrees 3, 3, 3 and 1?
3 + 3 + 3 + 1 = 10
The sum is even, so the handshaking lemma does not rule it out.
\deg(v) \le 3
With 4 vertices, a vertex of a simple graph has at most 3 neighbors.
u \sim \text{every other vertex}So each vertex u of degree 3 is adjacent to all three other vertices.
\deg(w) \ge 3
The last vertex w is then adjacent to all three degree-3 vertices.
\deg(w) = 1
But the list says w has degree 1, a contradiction (see proof by contradiction).
Answer: no such simple graph exists. An even degree sum is necessary, but it does not guarantee that a simple graph exists.
Example 4: A round-robin tournament (word problem)
In a round-robin tournament, each of 8 teams plays every other team exactly once. How many games are played?
\deg(v) = 7
Model teams as vertices and games as edges; each team plays the other 7 teams.
8 \cdot 7 = 56
Add the degrees of the 8 vertices.
2|E| = 56
Apply the handshaking lemma.
|E| = 28
Divide both sides by 2.
\binom{8}{2} = \dfrac{8 \cdot 7}{2}Check: each game is a choice of 2 teams from 8 (see combinations).
\dfrac{8 \cdot 7}{2} = 28Simplify: the same count.
Answer: 28 games. The tournament is the complete graph K_8.
Example 5: Handshakes at a party (word problem)
Nine people meet at a party. Can each person shake hands with exactly 5 of the others?
9 \cdot 5 = 45
People are vertices and handshakes are edges; add the 9 degrees.
2|E| = 45
The handshaking lemma says the degree sum is twice the number of handshakes.
45 \text{ is odd}An odd number cannot equal twice a whole number.
Answer: no. Nine vertices of odd degree would break the corollary, which allows only an even number of odd-degree vertices.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Counting a loop once | “A vertex with a loop and one other edge has degree 2.” | A loop adds 2 to the degree, so the degree is 3. |
| Forgetting to halve the degree sum | “The degrees are 3, 3, 2, 2, so there are 10 edges.” | 10 is 2|E|; there are 5 edges. |
| Thinking an even sum guarantees a graph | “3, 3, 3, 1 adds to 10, so a simple graph has these degrees.” | An even sum is needed but not enough; see Example 3. |
| Counting both ends in K_n | “K_8 has 8 · 7 = 56 edges.” | Each edge was counted from both ends: 56 ÷ 2 = 28. |
| Thinking odd degrees are not allowed | “No vertex can have degree 3.” | Odd degrees are fine; only the number of odd-degree vertices must be even. |
| Reading a crossing as a vertex | “Two edges cross, so they share a vertex.” | Only the marked dots are vertices; edges may cross in a drawing. |
Related ideas
Later lessons ask when a graph can be drawn with no edges crossing (planar graphs) and when a route can use every edge exactly once (Euler paths and circuits).
Directed graphs
In a directed graph, each edge has a direction, like a one-way street. A vertex has an out-degree (edges leaving it) and an in-degree (edges arriving). Each edge leaves one vertex and arrives at one, so both sums equal |E|. For the streets P → Q, Q → R, R → P, R → S and S → P, the out-degrees 1, 1, 2, 1 and the in-degrees 2, 1, 1, 1 each add to 5.
Graphs and relations
A graph is a picture of a relation on V. A simple graph matches a symmetric relation with no loops, and a directed graph matches any relation. The Hasse diagrams of the last lesson are graphs drawn to show an order.
Two vertices with the same degree
In every simple graph with at least 2 vertices, two vertices share a degree. The n degrees lie in 0, 1, …, n − 1, but 0 and n − 1 cannot both occur, since a vertex of degree n − 1 is adjacent to everything. So n vertices fill at most n − 1 values, and the pigeonhole principle gives a repeat.
The next lesson, Graph Isomorphism, stores graphs as adjacency matrices and decides when two drawings show the same graph.
Practice problems
- Find the degree of each vertex of the graph with V = {1, 2, 3, 4} and E = {{1, 2}, {1, 3}, {1, 4}, {2, 3}}, and check the handshaking lemma.
- In the five-vertex graph from Example 1, find a path of length 3 from A to E and a cycle of length 4.
- A graph has 12 edges. What is the sum of the degrees of its vertices?
- A graph has 6 vertices, each of degree 4. How many edges does it have?
- Can any graph have vertices of degrees 5, 4, 3, 2 and 1?
- How many edges does the complete graph K_{10} have?
- A graph has 11 edges. Four vertices have degree 3, and every other vertex has degree 2. How many vertices does it have?
- A multigraph has vertices u, v and w, a loop at v, and edges vu, vw and uw. Find each degree and check the handshaking lemma.
- Is there a simple graph with six vertices, each of degree 3? If so, describe one.
- In a club of 15 students, each student says they are friends with exactly 3 other members. Can every student be telling the truth?
Show answers
1.
\deg(1) = 3
Vertex 1 is in {1, 2}, {1, 3} and {1, 4}.
\deg(2) = 2
Vertex 2 is in {1, 2} and {2, 3}.
\deg(3) = 2
Vertex 3 is in {1, 3} and {2, 3}.
\deg(4) = 1
Vertex 4 is only in {1, 4}.
3 + 2 + 2 + 1 = 8
Add the degrees.
2 \cdot 4 = 8
Twice the 4 edges: the lemma checks.
Answer: degrees 3, 2, 2, 1; the sum 8 is twice the 4 edges
2.
A, B, D, E
Edges AB, BD and DE all exist: 3 edges.
A, B, D, C, A
Edges AB, BD, DC and CA all exist: 4 edges, back to the start.
Answer: the path A, B, D, E (or A, C, D, E) and the cycle A, B, D, C, A
3.
\textstyle\sum \deg(v) = 2|E|
Apply the handshaking lemma.
2 \cdot 12 = 24
Substitute 12 edges.
Answer: 24
4.
6 \cdot 4 = 24
Add the degrees.
2|E| = 24
Apply the handshaking lemma.
|E| = 12
Divide both sides by 2.
Answer: 12 edges
5.
5 + 4 + 3 + 2 + 1 = 15
Add the degrees.
15 \text{ is odd}A degree sum must equal 2|E|, which is even.
Answer: no
6.
\deg(v) = 9
Each vertex is adjacent to the other 9.
10 \cdot 9 = 90
Add the degrees.
2|E| = 90
Apply the handshaking lemma.
|E| = 45
Divide both sides by 2.
Answer: 45 edges
7.
2 \cdot 11 = 22
The handshaking lemma gives the degree sum.
4 \cdot 3 = 12
The degree-3 vertices contribute 12.
22 - 12 = 10
Degree left for the other vertices.
10 \div 2 = 5
Each of them has degree 2, so there are 5 of them.
4 + 5 = 9
Add the two groups of vertices.
Answer: 9 vertices
8.
\deg(v) = 2 + 1 + 1
The loop counts twice, plus edges vu and vw.
\deg(v) = 4
Add.
\deg(u) = 2
Edges vu and uw.
\deg(w) = 2
Edges vw and uw.
4 + 2 + 2 = 8
Add the degrees.
2 \cdot 4 = 8
There are 4 edges (the loop, vu, vw and uw), and twice that matches.
Answer: deg(v) = 4, deg(u) = deg(w) = 2; the lemma checks
9.
6 \cdot 3 = 18
The degree sum is even, so the lemma allows it.
|E| = 9
Divide by 2.
\text{triangles } ABC,\ DEFDraw two triangles; each vertex now has degree 2.
AD,\ BE,\ CF
Join the triangles with three edges; each vertex gains 1.
3 + 6 = 9
Count the edges: 6 triangle edges and 3 joining edges.
Answer: yes; two triangles joined by three edges (a triangular prism) has every degree 3 and 9 edges
10.
15 \cdot 3 = 45
Students are vertices and friendships are edges; add the degrees.
45 \text{ is odd}The degree sum must be 2|E|, which is even.
Answer: no; at least one student is wrong
Graph theory basics FAQ
What is the handshaking lemma?
It says the degrees of all the vertices of a graph add up to twice the number of edges, because each edge is counted once at each of its two ends.
What is the degree of a vertex?
It is the number of edges that touch the vertex. A loop counts twice, because both of its ends are at that vertex.
Can a graph have an odd number of vertices of odd degree?
No. The handshaking lemma makes the degree sum even, so vertices of odd degree always come in an even number.
How many edges does a complete graph have?
The complete graph on n vertices has n(n − 1)/2 edges. For example, K_5 has 10 edges and K_8 has 28.
Summary
- A graph is a set of vertices joined by edges; a simple graph has no loops and no multiple edges.
- The degree of a vertex is the number of edges touching it, with a loop counted twice.
- Handshaking lemma: the degree sum equals 2|E|.
- Every graph has an even number of vertices of odd degree.
- An odd degree sum rules a graph out, but an even sum does not prove one exists.
- The complete graph K_n has n(n − 1)/2 edges.
Previous lesson: Partial Orders
Next lesson: Graph Isomorphism
Back to the Discrete Math Index