MAT2033 · Week 13 · Introduction to graphs, graph isomorphisms

Introduction to graphs and graph isomorphism

Graph terminology, degree and the handshaking theorem, special graphs (K_n, C_n, W_n, Q_n, K_{m,n}), bipartite graphs, adjacency matrices, and showing whether two graphs are isomorphic.

graphvertexedgesimple graphmultigraphpseudographdirected graphadjacentdegreehandshaking theoremin-degreeout-degreecomplete graphcyclewheeln-cubebipartite graphcomplete bipartite graphregular graphsubgraphcomplementadjacency matrixadjacency listisomorphismgraph invariant

Graph theory is the last big block of the final. This week you learn the language: vertices, edges, degree, special graphs, and when two graphs are “the same” (isomorphism). Next week, paths, Euler and Hamilton questions will come in this language. It is not on the midterm, it is a final exam topic. The exam questions are short and computational: “How many edges?”, “Is it bipartite?”, “Are these graphs isomorphic?”.

Golden rules:

  1. Handshaking theorem: the sum of the degrees is twice the number of edges.
  2. So the number of odd-degree vertices is even.
  3. Bipartite   ⟺  \iff no odd cycle   ⟺  \iff 2-colorable.
  4. To say not isomorphic, it is enough for a single invariant to differ. To show they are isomorphic, you must write the mapping.

Basic definitions

A graph G=(V,E)G = (V, E): a set of vertices VV and a set of edges EE, each connecting one or two vertices.

TypeParallel edgesLoopsDirected
simple graphnonono
multigraphyesnono
pseudographyesyesno
directed graphpossiblepossibleyes

Two vertices with an edge between them are adjacent. The degree deg⁡(v)\deg(v) of a vertex is the number of edges touching it; a loop adds 2 to the degree. A vertex of degree 0 is isolated, one of degree 1 is pendant.

Intuition: vertices are teammates, edges are “having passed to each other”. The degree is the number of different people a player exchanges passes with.

The handshaking theorem

2m=∑v∈Vdeg⁡(v),m=∣E∣.2m = \sum_{v\in V} \deg(v), \qquad m = |E|.

Every edge has two ends, and each end adds 1 to the degree of a vertex. In directed graphs the in-degree deg⁡−(v)\deg^-(v) and out-degree deg⁡+(v)\deg^+(v) are separate: ∑deg⁡−(v)=∑deg⁡+(v)=m\sum \deg^-(v) = \sum \deg^+(v) = m.

Example. V={a,b,c,d,e}V = \{a,b,c,d,e\}, E={ab,ac,bc,cd,de}E = \{ab, ac, bc, cd, de\}:

deg(a) = 2  (b, c)
deg(b) = 2  (a, c)
deg(c) = 3  (a, b, d)
deg(d) = 2  (c, e)
deg(e) = 1  (d)      -> pendant
total = 10 = 2 * 5 edges
odd-degree vertices: c, e  -> 2 of them (even)

A fully written proof

Theorem. An undirected graph has an even number of vertices of odd degree.

Proof. Let V1V_1 be the set of vertices of even degree and V2V_2 the set of vertices of odd degree in G=(V,E)G = (V,E) with mm edges. By the handshaking theorem, 2m=∑v∈V1deg⁡(v)+∑v∈V2deg⁡(v).2m = \sum_{v\in V_1}\deg(v) + \sum_{v\in V_2}\deg(v). The left side is even. The first sum on the right is even, since each of its terms is even. Hence the second sum is the difference of two even numbers, so it is even. Every term of the second sum is odd, and a sum of odd numbers is even only if the number of terms is even. Therefore ∣V2∣|V_2| is even. ■\blacksquare

In plain words: split the total into even and odd parts, remove the even part, and what remains, a sum of odd numbers, must be even. That happens only with an even number of odd terms. On the exam you use this theorem in a question like “Is there a graph with degrees 3, 3, 2, 1, 1, 1?”: there are 5 odd-degree vertices, impossible.

PITFALL · Thinking a graph exists because the sum is even. The sum of the sequence 3,3,3,13,3,3,1 is 10, even. But in a simple graph with 4 vertices, degree 3 means “connected to everyone”, and then the last vertex would also have degree 3. An even sum is a necessary condition, not sufficient.

Special graphs

GraphDefinitionVerticesEdgesDegrees
KnK_n (complete)every pair adjacentnnn(n−1)2\frac{n(n-1)}{2}all n−1n-1
CnC_n (cycle), n≥3n\ge 3v1v2…vnv1v_1v_2\dots v_nv_1nnnnall 2
WnW_n (wheel)CnC_n + a center connected to alln+1n+12n2ncenter nn, others 3
QnQ_n (n-cube)bit strings of length nn, a one-bit difference = edge2n2^nn2n−1n2^{n-1}all nn
Km,nK_{m,n} (complete bipartite)two groups of mm and nn vertices, every edge between groupsm+nm+nmnmnnn and mm

A graph whose degrees are all equal is called regular: KnK_n, CnC_n, QnQ_n are regular; WnW_n (n≠3n \neq 3) is not.

Check: K5K_5 has 10 edges, Q3Q_3 has 12 edges, W4W_4 has 5 vertices and 8 edges.

Bipartite graphs

If VV can be split into two disjoint sets V1,V2V_1, V_2 and every edge connects a vertex in V1V_1 to a vertex in V2V_2, the graph is bipartite. Equivalent definition: you can color the vertices with two colors so that neighbors have different colors.

Theorem: A graph is bipartite if and only if it contains no cycle of odd length.

Practical test: make one vertex red, its neighbors blue, their neighbors red… If two neighbors of the same color appear, it is not bipartite.

C6:  1R 2B 3R 4B 5R 6B, edge 6-1 is B-R   -> bipartite
C5:  1R 2B 3R 4B 5R, edge 5-1 is R-R      -> NOT bipartite
K3:  triangle = cycle of length 3          -> NOT bipartite

Representing a graph

Adjacency list: the neighbors of each vertex. Efficient for sparse graphs.

Adjacency matrix AA: aij=1a_{ij} = 1 if the edge vivjv_i v_j exists, otherwise 0. The example graph above (in the order a,b,c,d,ea,b,c,d,e):

A=[0110010100110100010100010]A = \begin{bmatrix} 0&1&1&0&0\\ 1&0&1&0&0\\ 1&1&0&1&0\\ 0&0&1&0&1\\ 0&0&0&1&0 \end{bmatrix}

For an undirected graph AA is symmetric; for a simple graph the diagonal is 0 and the row sum gives the degree. In a multigraph aija_{ij} is the number of parallel edges. The incidence matrix is a vertex × edge table: mij=1m_{ij} = 1 if the edge eje_j touches viv_i.

Subgraph: a graph made of subsets of VV and EE. Complement G‾\overline{G}: the same vertices, all the edges that are not in GG. m(G)+m(G‾)=n(n−1)2m(G) + m(\overline{G}) = \frac{n(n-1)}{2}.

Graph isomorphism

G1=(V1,E1)G_1 = (V_1,E_1) and G2=(V2,E2)G_2 = (V_2,E_2) are isomorphic if there is a one-to-one and onto f:V1→V2f: V_1\to V_2 such that

uv∈E1  ⟺  f(u)f(v)∈E2.uv \in E_1 \iff f(u)f(v)\in E_2.

Intuition: the same graph, with the vertices named differently and drawn differently on paper.

Showing not isomorphic: invariants

A graph invariant is a property preserved by isomorphism. If one differs, the graphs cannot be isomorphic.

InvariantCheck
number of vertices, number of edgescount
degree sequencesort, compare
whether there is a cycle of a given lengthespecially a triangle (length 3)
connectivity, number of componentsnext week
whether bipartite2-coloring
the degrees of the neighbors of the vertices of degree kka finer check

Example. C6C_6 and two disjoint triangles (2K32K_3). Both have 6 vertices, 6 edges, all degrees 2. But C6C_6 is connected and has no triangle; 2K32K_3 has two components and contains triangles. Not isomorphic.

Showing isomorphic

All invariants being the same is not a proof. You must write the mapping and check every edge. Method:

  1. Check that the degree sequences are the same.
  2. Start with vertices of unique degree (degree 3 → degree 3).
  3. Preserve adjacencies: the neighbors of uu must go to the neighbors of f(u)f(u).
  4. Last step: translate all the edges one by one and write that they are in E2E_2. If you like, with matrices: when you list the vertices in the order of ff, the two adjacency matrices must be the same.

The GG and HH example in the questions is solved with exactly this method.

TIP · the complement trick. If comparing two graphs with many edges is hard, look at their complements. G1≅G2  ⟺  G1‾≅G2‾G_1 \cong G_2 \iff \overline{G_1}\cong\overline{G_2}, and the complements are sparser.

Common mistakes

WrongThe truth
Counting a loop as 1 in the degreeA loop adds 2 to the degree
The total degree is even, so the graph existsA necessary condition; the sequence 3,3,3,13,3,3,1 is not a simple graph
WnW_n has nn verticesn+1n+1 vertices (including the center), 2n2n edges
QnQ_n has 2n2^n edges2n2^n vertices, n2n−1n2^{n-1} edges
Same degree sequence, so isomorphicOnly necessary; the K3,3K_{3,3} and prism example
Skipping the edge check when showing an isomorphismWrite the image of every edge
CnC_n is always bipartiteOnly if nn is even
In a directed graph in + out = mEach separately equals mm

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

A simple graph has vertex degrees 4, 3, 3, 2, 2. How many edges does it have?

Show answer
7

Handshaking theorem: 2m=∑deg⁡(v)=4+3+3+2+2=142m = \sum \deg(v) = 4+3+3+2+2 = 14, so m=7m = 7.

Question 2easy

How many vertices and edges do K7K_7, Q4Q_4, W6W_6 and K3,5K_{3,5} have?

Show answer
K7: 7, 21; Q4: 16, 32; W6: 7, 12; K3,5: 8, 15

KnK_n: nn vertices, n(n−1)2\frac{n(n-1)}{2} edges, 2121 for K7K_7.QnQ_n: 2n2^n vertices, every vertex has degree nn, edges n2n−1n 2^{n-1}: for Q4Q_4, 1616 vertices and 4⋅8=324\cdot 8 = 32 edges.WnW_n: CnC_n + center, n+1n+1 vertices, 2n2n edges: for W6W_6, 77 and 1212.Km,nK_{m,n}: m+nm+n vertices, mnmn edges: 88 and 1515.

Question 3easy

Is there a simple graph with 9 vertices, each of degree 3? With 10 vertices, each of degree 3?

Show answer
No for 9 vertices; yes for 10 (15 edges)

9 vertices: the degree sum is 9⋅3=279\cdot 3 = 27, odd. The sum must always be 2m2m (even), so it is impossible.
10 vertices: the sum is 3030, m=15m = 15. Example: take C10C_{10} and connect each vertex ii to the opposite vertex i+5i+5; every vertex gets degree 3.

Question 4medium

Which of the following graphs are bipartite: C6C_6, C5C_5, K3K_3, Q3Q_3, K2,3K_{2,3}?

Show answer
C6, Q3, K2,3

A graph is bipartite if and only if it contains no cycle of odd length (odd cycle).C6C_6: an even cycle, give two colors in turn, it works. C5C_5 and K3K_3: odd cycles, not possible.Q3Q_3: split the bit strings by the parity of the number of 1s; every edge changes a single bit, so the parity changes. Bipartite.K2,3K_{2,3}: bipartite by definition.

Question 5hard

Can a simple graph have degree sequence 3,3,3,13, 3, 3, 1?

Show answer
No

The sum 1010 is even, so the first check passes, but it is not enough. In a simple graph with 4 vertices, degree 3 means the vertex is connected to all three other vertices.
Each of the three vertices of degree 3 would also have to be connected to the vertex of degree 1, which would then have degree 3, not 1. Contradiction, so there is no such graph.

Question 6easy

The adjacency matrix of a simple graph with vertices v1,…,v5v_1, \dots, v_5 is[0110110100110110010110110].\begin{bmatrix} 0&1&1&0&1\\ 1&0&1&0&0\\ 1&1&0&1&1\\ 0&0&1&0&1\\ 1&0&1&1&0 \end{bmatrix}.Find the degree of each vertex and the number of edges.

Show answer
Degrees 3, 2, 4, 2, 3; 7 edges

In a simple graph, deg⁡(vi)\deg(v_i) = the number of 1s in row ii: 3,2,4,2,33, 2, 4, 2, 3.
The sum is 1414, so the number of edges is 14/2=714/2 = 7. (The matrix is symmetric with a zero diagonal: no loops.)

Question 7medium

GG has vertices u1,…,u5u_1,\dots,u_5 and edges u1u2,u2u3,u3u4,u4u5,u5u1,u1u3u_1u_2, u_2u_3, u_3u_4, u_4u_5, u_5u_1, u_1u_3. HH has vertices v1,…,v5v_1,\dots,v_5 and edges v1v3,v3v5,v5v2,v2v4,v4v1,v4v5v_1v_3, v_3v_5, v_5v_2, v_2v_4, v_4v_1, v_4v_5. Show that GG and HH are isomorphic by giving an isomorphism.

Show answer
f(u1)=v4, f(u2)=v2, f(u3)=v5, f(u4)=v3, f(u5)=v1

Invariants: both have 5 vertices, 6 edges, and degree sequence 3,3,2,2,23,3,2,2,2. In GG the vertices of degree 3 are u1,u3u_1, u_3 (adjacent); in HH they are v4,v5v_4, v_5 (adjacent).u1↦v4u_1 \mapsto v_4, u3↦v5u_3\mapsto v_5. u2u_2 is the common neighbor of u1u_1 and u3u_3; in HH the common neighbor of v4v_4 and v5v_5 is v2v_2: u2↦v2u_2\mapsto v_2.u4u_4 is adjacent to u3u_3: the remaining neighbor of v5v_5 is v3v_3. u5↦v1u_5 \mapsto v_1.
Edge check: u1u2→v4v2u_1u_2\to v_4v_2, u2u3→v2v5u_2u_3\to v_2v_5, u3u4→v5v3u_3u_4\to v_5v_3, u4u5→v3v1u_4u_5\to v_3v_1, u5u1→v1v4u_5u_1\to v_1v_4, u1u3→v4v5u_1u_3\to v_4v_5. All are in HH.

Question 8medium

Both K3,3K_{3,3} and the triangular prism (two triangles 123123, 456456 joined by edges 14,25,3614, 25, 36) are 3-regular graphs with 6 vertices and 9 edges. Are they isomorphic?

Show answer
No

The vertices, edges and degree sequence are the same; these are necessary but not sufficient for isomorphism.
The prism contains a triangle (K3K_3, a cycle of length 3). K3,3K_{3,3} is bipartite and has no odd cycles. "Contains a cycle of length 3" is an invariant; one satisfies it and the other does not: they are not isomorphic.

Question 9hard

How many non-isomorphic simple graphs with 4 vertices are there?

Show answer
11

Count by number of edges (from 00 to 66; graphs with mm and 6−m6-m edges are paired by complement):
0 edges: 1. 1 edge: 1. 2 edges: 2 (two adjacent edges, two disjoint edges). 3 edges: 3 (triangle + isolated vertex, path P4P_4, star K1,3K_{1,3}).
4 edges: 2, 5 edges: 1, 6 edges: 1 (from the complements). Total 1+1+2+3+2+1+1=111+1+2+3+2+1+1 = 11.

Question 10easy

A simple graph has 8 vertices and 10 edges. How many edges does its complement have?

Show answer
18

G∪G‾=K8G \cup \overline{G} = K_8, and K8K_8 has 8⋅72=28\frac{8\cdot 7}{2} = 28 edges. G‾\overline{G} has 28−10=1828 - 10 = 18 edges.

Question 11medium

A directed graph has edges (a,b),(a,c),(b,c),(c,a),(c,d),(d,d)(a,b), (a,c), (b,c), (c,a), (c,d), (d,d). Find the in-degree and out-degree of each vertex.

Show answer
out: a2, b1, c2, d1; in: a1, b1, c2, d2

deg⁡+(v)\deg^+(v): the number of edges leaving vv, deg⁡−(v)\deg^-(v): the number of edges entering vv.
Out: aa: (a,b),(a,c)(a,b),(a,c) = 2. bb: 1. cc: (c,a),(c,d)(c,a),(c,d) = 2. dd: the loop (d,d)(d,d) = 1.
In: aa: 1, bb: 1, cc: (a,c),(b,c)(a,c),(b,c) = 2, dd: (c,d),(d,d)(c,d),(d,d) = 2.
Check: both sums are 66 = the number of edges. A loop adds 1 to both in and out.

Question 12medium

For which values of m,nm, n is Km,nK_{m,n} regular? How many edges does Q5Q_5 have?

Show answer
m = n; 80 edges

In Km,nK_{m,n} the vertices on one side have degree nn and those on the other side have degree mm. All are equal only if m=nm = n.Q5Q_5: 25=322^5 = 32 vertices, each of degree 5. Handshaking: 2m=32⋅5=1602m = 32\cdot 5 = 160, m=80m = 80 (formula n2n−1=5⋅16n 2^{n-1} = 5\cdot 16).

Verification: Degrees, edge counts and special graph formulas were computed with node by building the graphs; bipartiteness by BFS 2-coloring, isomorphisms by trying all vertex permutations, the number of non-isomorphic graphs on 4 vertices (11) by counting canonical forms of the 64 labeled graphs, and the impossibility of the sequence 3,3,3,1 by scanning all graphs (verify/MAT2033/13.mjs).

Review card

Simple graph: no loops, no parallel edges. Multigraph: parallel allowed. Pseudograph: loops too deg(v) = number of incident edges; a loop counts 2 Handshaking: sum of degrees = 2m -> the number of odd-degree vertices is EVEN Directed: total in = total out = m K_n: n(n-1)/2 edges | C_n: n | W_n: n+1 vertices, 2n edges | Q_n: 2^n vertices, n 2^(n-1) edges | K_{m,n}: mn Bipartite <=> 2-colorable <=> no odd cycle Complement: m(G) + m(G') = n(n-1)/2 Adjacency matrix: symmetric (undirected), row sum = degree Isomorphism: an edge-preserving bijection f: V -> V' Invariants: vertices, edges, degree sequence, cycle lengths, connectivity, being bipartite Invariant differs -> NOT isomorphic. All the same -> still write f and check the edges Map degree 3 to degree 3, adjacency to adjacency