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.
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:
- Handshaking theorem: the sum of the degrees is twice the number of edges.
- So the number of odd-degree vertices is even.
- Bipartite no odd cycle 2-colorable.
- 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 : a set of vertices and a set of edges , each connecting one or two vertices.
| Type | Parallel edges | Loops | Directed |
|---|---|---|---|
| simple graph | no | no | no |
| multigraph | yes | no | no |
| pseudograph | yes | yes | no |
| directed graph | possible | possible | yes |
Two vertices with an edge between them are adjacent. The degree 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
Every edge has two ends, and each end adds 1 to the degree of a vertex. In directed graphs the in-degree and out-degree are separate: .
Example. , :
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 be the set of vertices of even degree and the set of vertices of odd degree in with edges. By the handshaking theorem, 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 is even.
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 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
| Graph | Definition | Vertices | Edges | Degrees |
|---|---|---|---|---|
| (complete) | every pair adjacent | all | ||
| (cycle), | all 2 | |||
| (wheel) | + a center connected to all | center , others 3 | ||
| (n-cube) | bit strings of length , a one-bit difference = edge | all | ||
| (complete bipartite) | two groups of and vertices, every edge between groups | and |
A graph whose degrees are all equal is called regular: , , are regular; () is not.
Check: has 10 edges, has 12 edges, has 5 vertices and 8 edges.
Bipartite graphs
If can be split into two disjoint sets and every edge connects a vertex in to a vertex in , 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 : if the edge exists, otherwise 0. The example graph above (in the order ):
For an undirected graph is symmetric; for a simple graph the diagonal is 0 and the row sum gives the degree. In a multigraph is the number of parallel edges. The incidence matrix is a vertex × edge table: if the edge touches .
Subgraph: a graph made of subsets of and . Complement : the same vertices, all the edges that are not in . .
Graph isomorphism
and are isomorphic if there is a one-to-one and onto such that
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.
| Invariant | Check |
|---|---|
| number of vertices, number of edges | count |
| degree sequence | sort, compare |
| whether there is a cycle of a given length | especially a triangle (length 3) |
| connectivity, number of components | next week |
| whether bipartite | 2-coloring |
| the degrees of the neighbors of the vertices of degree | a finer check |
Example. and two disjoint triangles (). Both have 6 vertices, 6 edges, all degrees 2. But is connected and has no triangle; 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:
- Check that the degree sequences are the same.
- Start with vertices of unique degree (degree 3 → degree 3).
- Preserve adjacencies: the neighbors of must go to the neighbors of .
- Last step: translate all the edges one by one and write that they are in . If you like, with matrices: when you list the vertices in the order of , the two adjacency matrices must be the same.
The and 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. , and the complements are sparser.
Common mistakes
| Wrong | The truth |
|---|---|
| Counting a loop as 1 in the degree | A loop adds 2 to the degree |
| The total degree is even, so the graph exists | A necessary condition; the sequence is not a simple graph |
| has vertices | vertices (including the center), edges |
| has edges | vertices, edges |
| Same degree sequence, so isomorphic | Only necessary; the and prism example |
| Skipping the edge check when showing an isomorphism | Write the image of every edge |
| is always bipartite | Only if is even |
| In a directed graph in + out = m | Each separately equals |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
A simple graph has vertex degrees 4, 3, 3, 2, 2. How many edges does it have?
Show answer
Handshaking theorem: , so .
How many vertices and edges do , , and have?
Show answer
: vertices, edges, for .: vertices, every vertex has degree , edges : for , vertices and edges.: + center, vertices, edges: for , and .: vertices, edges: and .
Is there a simple graph with 9 vertices, each of degree 3? With 10 vertices, each of degree 3?
Show answer
9 vertices: the degree sum is , odd. The sum must always be (even), so it is impossible.
10 vertices: the sum is , . Example: take and connect each vertex to the opposite vertex ; every vertex gets degree 3.
Which of the following graphs are bipartite: , , , , ?
Show answer
A graph is bipartite if and only if it contains no cycle of odd length (odd cycle).: an even cycle, give two colors in turn, it works. and : odd cycles, not possible.: split the bit strings by the parity of the number of 1s; every edge changes a single bit, so the parity changes. Bipartite.: bipartite by definition.
Can a simple graph have degree sequence ?
Show answer
The sum 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.
The adjacency matrix of a simple graph with vertices isFind the degree of each vertex and the number of edges.
Show answer
In a simple graph, = the number of 1s in row : .
The sum is , so the number of edges is . (The matrix is symmetric with a zero diagonal: no loops.)
has vertices and edges . has vertices and edges . Show that and are isomorphic by giving an isomorphism.
Show answer
Invariants: both have 5 vertices, 6 edges, and degree sequence . In the vertices of degree 3 are (adjacent); in they are (adjacent)., . is the common neighbor of and ; in the common neighbor of and is : . is adjacent to : the remaining neighbor of is . .
Edge check: , , , , , . All are in .
Both and the triangular prism (two triangles , joined by edges ) are 3-regular graphs with 6 vertices and 9 edges. Are they isomorphic?
Show answer
The vertices, edges and degree sequence are the same; these are necessary but not sufficient for isomorphism.
The prism contains a triangle (, a cycle of length 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.
How many non-isomorphic simple graphs with 4 vertices are there?
Show answer
Count by number of edges (from to ; graphs with and 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 , star ).
4 edges: 2, 5 edges: 1, 6 edges: 1 (from the complements). Total .
A simple graph has 8 vertices and 10 edges. How many edges does its complement have?
Show answer
, and has edges. has edges.
A directed graph has edges . Find the in-degree and out-degree of each vertex.
Show answer
: the number of edges leaving , : the number of edges entering .
Out: : = 2. : 1. : = 2. : the loop = 1.
In: : 1, : 1, : = 2, : = 2.
Check: both sums are = the number of edges. A loop adds 1 to both in and out.
For which values of is regular? How many edges does have?
Show answer
In the vertices on one side have degree and those on the other side have degree . All are equal only if .: vertices, each of degree 5. Handshaking: , (formula ).
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).