Skip to content

Graph Theory | Computer Science

A graph G=(V,E)G = (V, E) consists of a set of vertices VV and a set of edges EV×VE \subseteq V \times V.

  • Simple graph: no loops, no multiple edges.
  • Directed graph (digraph): edges have direction.
  • Weighted graph: edges have weights.

The degree of a vertex vv, deg(v)\deg(v)Is the number of edges incident to vv.

Theorem 5.1 (Handshaking Lemma). vVdeg(v)=2E\sum_{v \in V} \deg(v) = 2|E|.

Proof. Each edge contributes 1 to the degree of each of its two endpoints. \blacksquare

Corollary 5.2. The number of vertices of odd degree is even.

A walk is a sequence of vertices where consecutive vertices are adjacent. A path is a walk With no repeated vertices. A cycle is a path that returns to its starting vertex.

A graph is connected if there is a path between every pair of vertices. A connected component Is a maximal connected subgraph.

Theorem 5.3. A graph with nn vertices and more than (n1)(n2)/2(n-1)(n-2)/2 edges is connected.

A tree is a connected acyclic graph. A forest is a disjoint union of trees.

Theorem 5.4. For a graph GG with nn vertices, the following are equivalent:

  1. GG is a tree.
  2. GG is connected and has n1n - 1 edges.
  3. GG is acyclic and has n1n - 1 edges.
  4. Between any two vertices, there is exactly one path.

Cayley”s Formula. The number of labelled trees on nn vertices is nn2n^{n-2}.

A graph is planar if it can be drawn in the plane with no edge crossings.

Theorem 5.5 (Euler’s Formula for Planar Graphs). For a connected planar graph drawn in the plane With VV vertices, EE edges, and FF faces:

VE+F=2V - E + F = 2

Proof sketch. Build the graph edge by edge. Starting from a single vertex (V=1V = 1, E=0E = 0, F=1F = 1), The quantity VE+F=2V - E + F = 2 is preserved when adding an edge: if the edge connects two components, EE and VV each increase by 1; if it splits a face, EE and FF each increase by 1. \blacksquare

Corollary 5.6. For a simple planar graph with V3V \geq 3: E3V6E \leq 3V - 6.

Proof. Every face has at least 3 edges on its boundary, and every edge borders at most 2 faces, So 3F2E3F \leq 2E. By Euler’s formula, F=2V+EF = 2 - V + EGiving 3(2V+E)2E3(2 - V + E) \leq 2EI.e., E3V6E \leq 3V - 6. \blacksquare

Corollary 5.7. K5K_5 and K3,3K_{3,3} are not planar.

Proof. K5K_5 has V=5V = 5, E=10E = 10 But 10>3(5)6=910 \gt 3(5) - 6 = 9. For K3,3K_{3,3}, V=6V = 6, E=9E = 9. Since K3,3K_{3,3} has no triangles, every face has at least 4 edges, giving 4F2E4F \leq 2E So FE/2=4.5F \leq E/2 = 4.5. But VE+F=2V - E + F = 2 gives F=26+9=5>4.5F = 2 - 6 + 9 = 5 \gt 4.5. Contradiction. \blacksquare

Theorem 5.8 (Kuratowski’s Theorem). A graph is planar if and only if it does not contain a Subdivision of K5K_5 or K3,3K_{3,3} as a subgraph.

A subdivision of an edge uvuv replaces uvuv with a path uuwwvv through a new vertex ww. A graph HH is a subdivision of GG if HH can be obtained from GG by subdividing edges.

Worked Example. Show that K3,3K_{3,3} is not planar using Euler’s formula.

Solution

K3,3K_{3,3} has V=6V = 6 vertices and E=9E = 9 edges. It is bipartite (partition sizes 3 and 3), so it Contains no triangles. Every face in a planar embedding must therefore be bounded by at least 4 edges, Giving 4F2E4F \leq 2EI.e., F9/2=4.5F \leq 9/2 = 4.5.

But Euler’s formula gives F=EV+2=96+2=5F = E - V + 2 = 9 - 6 + 2 = 5. Since 5>4.55 \gt 4.5No planar embedding Exists. \blacksquare

A proper kk-colouring assigns one of kk colours to each vertex such that adjacent vertices have Different colours. The chromatic number χ(G)\chi(G) is the minimum kk for which a proper kk-colouring Exists.

Theorem 5.9 (Four Colour Theorem). Every planar graph is 4-colourable.

Theorem 5.10 (Five Colour Theorem). Every planar graph is 5-colourable. (Easier to prove.)

Theorem 5.11 (Greedy Colouring Bound). χ(G)Δ(G)+1\chi(G) \leq \Delta(G) + 1 where Δ(G)\Delta(G) is the Maximum degree.

Theorem 5.12 (Brooks’ Theorem). If GG is connected and is neither a complete graph nor an odd Cycle, then χ(G)Δ(G)\chi(G) \leq \Delta(G).

Chromatic polynomial. The chromatic polynomial P(G,k)P(G, k) counts the number of proper kk-colourings of GG.

Theorem 5.13. P(G,k)P(G, k) is a polynomial in kk.

Deletion-contraction recurrence. For any edge ee of GG:

P(G,k)=P(Ge,k)P(G/e,k)P(G, k) = P(G - e, k) - P(G / e, k)

Where GeG - e is GG with edge ee deleted, and G/eG / e is GG with ee contracted (its endpoints Merged).

Worked Example. Find the chromatic polynomial of C4C_4 (the 4-cycle).

Solution

Label the vertices of C4C_4 as v1,v2,v3,v4v_1, v_2, v_3, v_4 with edges v1v2v_1v_2, v2v3v_2v_3, v3v4v_3v_4, v4v1v_4v_1.

Pick edge e=v1v2e = v_1v_2.

GeG - e is a path on 4 vertices (a tree): P(Ge,k)=k(k1)3P(G - e, k) = k(k-1)^3.

G/eG / e merges v1v_1 and v2v_2Yielding C3C_3 (triangle): P(C3,k)=k(k1)(k2)P(C_3, k) = k(k-1)(k-2).

Therefore P(C4,k)=k(k1)3k(k1)(k2)=k(k1)[(k1)2(k2)]=k(k1)(k23k+3)P(C_4, k) = k(k-1)^3 - k(k-1)(k-2) = k(k-1)[(k-1)^2 - (k-2)] = k(k-1)(k^2 - 3k + 3).

Checking: P(C4,2)=2(1)(46+3)=2P(C_4, 2) = 2(1)(4 - 6 + 3) = 2 (two 2-colourings: alternating), and P(C4,3)=32(99+3)=18P(C_4, 3) = 3 \cdot 2 \cdot (9 - 9 + 3) = 18. \blacksquare

Worked Example. Find χ(Kn)\chi(K_n) and χ(Km,n)\chi(K_{m,n}).

Solution

KnK_n (complete graph on nn vertices): every pair of vertices is adjacent, so all nn vertices must Receive distinct colours. Hence χ(Kn)=n\chi(K_n) = n.

Km,nK_{m,n} (complete bipartite graph): no two vertices within the same partition are adjacent, so we Can colour all vertices in the first partition with colour 1 and all in the second with colour 2. Hence χ(Km,n)=2\chi(K_{m,n}) = 2 (for m,n1m, n \geq 1).

Worked Example. Find the chromatic polynomial of K3K_3 (triangle).

Solution

Choose a colour for vertex 1: kk choices. Choose a colour for vertex 2 (different from vertex 1): k1k - 1 choices. Choose a colour for vertex 3 (different from both): k2k - 2 choices.

P(K3,k)=k(k1)(k2)P(K_3, k) = k(k-1)(k-2).

Checking: P(K3,2)=210=0P(K_3, 2) = 2 \cdot 1 \cdot 0 = 0 (not 2-colourable, as expected). P(K3,3)=6P(K_3, 3) = 6.

An Euler path visits every edge exactly once. An Euler circuit is an Euler path that starts And ends at the same vertex.

Theorem 5.14. A connected graph has an Euler circuit if and only if every vertex has even degree. It has an Euler path (but not circuit) if and only if exactly two vertices have odd degree.

Proof (sufficiency). If every vertex has even degree, start at any vertex and follow edges, never Reusing an edge. Since all degrees are even, the walk can only terminate at the starting vertex, Forming a circuit CC. If CC uses all edges, we are done. Otherwise, remove CC‘s edges; each Remaining component has all vertices of even degree (each lost an even number of incident edges). By induction, each component has an Euler circuit. Splicing these circuits into CC at shared Vertices yields an Euler circuit of the full graph. \blacksquare

Worked Example. Does K2,3K_{2,3} have an Euler circuit? An Euler path?

Solution

K2,3K_{2,3} has 5 vertices. The two vertices in the first partition each have degree 3 (connected to All three in the second partition). The three vertices in the second partition each have degree 2.

Vertices of odd degree: two (each of degree 3). Since exactly two vertices have odd degree, K2,3K_{2,3} has an Euler path (starting at one odd-degree vertex, ending at the other) but not an Euler circuit.

A Hamilton path visits every vertex exactly once. A Hamilton circuit is a Hamilton path that Returns to the start.

Theorem 5.15 (Dirac’s Theorem). If GG is a simple graph with n3n \geq 3 vertices and deg(v)n/2\deg(v) \geq n/2 for every vertex, then GG has a Hamilton circuit.

Theorem 5.16 (Ore’s Theorem). If GG is a simple graph with n3n \geq 3 vertices and deg(u)+deg(v)n\deg(u) + \deg(v) \geq n for every pair of non-adjacent vertices u,vu, v Then GG has a Hamilton Circuit.

Note that Dirac’s theorem is a corollary of Ore’s theorem.

Worked Example. Does K2,3K_{2,3} have a Hamilton circuit?

Solution

K2,3K_{2,3} has 5 vertices. A Hamilton circuit must visit all 5 vertices and return. Label the Partitions as A=a1,a2A = \\{a_1, a_2\\} and B=b1,b2,b3B = \\{b_1, b_2, b_3\\}. Any cycle in a bipartite graph alternates Between the two partitions. A Hamilton cycle would alternate between AA and BBRequiring A=B|A| = |B|. But A=23=B|A| = 2 \neq 3 = |B| So no Hamilton circuit exists.

However, K2,3K_{2,3} does have Hamilton paths (e.g., a1,b1,a2,b2,b3a_1, b_1, a_2, b_2, b_3 — wait, this doesn’t Alternate properly). Actually, in K2,3K_{2,3} edges only exist between AA and BB. A path must alternate A,B,A,B,A, B, A, B, \ldots or B,A,B,A,B, A, B, A, \ldots. A Hamilton path visits all 5 vertices, so it has the Form a,b,a,b,aa, b, a, b, a (length 5, starting and ending in AA) or b,a,b,a,bb, a, b, a, b (length 5, starting And ending in BB). The first requires 3 vertices from AA But A=2|A| = 2. The second requires 3 Vertices from BB And B=3|B| = 3. So a Hamilton path exists: e.g., b1,a1,b2,a2,b3b_1, a_1, b_2, a_2, b_3.

Worked Example. Let GG have vertices 1,2,3,4,5\\{1, 2, 3, 4, 5\\} and edges 12,23,34,45,51,13,3512, 23, 34, 45, 51, 13, 35. Does GG have an Euler circuit or Euler path?

Solution

Degrees: deg(1)=3\deg(1) = 3, deg(2)=2\deg(2) = 2, deg(3)=4\deg(3) = 4, deg(4)=2\deg(4) = 2, deg(5)=3\deg(5) = 3. Two vertices (1 and 5) have odd degree. Since exactly two vertices have odd degree, GG has an Euler Path (starting at 1, ending at 5) but no Euler circuit.

One Euler path: 123453151 \to 2 \to 3 \to 4 \to 5 \to 3 \to 1 \to 5. All 7 edges are used exactly once. ✓

Algorithm (Hierholzer’s). To find an Euler circuit: start at any vertex, follow unused edges Until returning to the start. If unused edges remain, find a vertex on the current circuit with Unused edges, find a subtour, and splice it in. Repeat until all edges are used.

flowchart TD
A[5_Graph Theory] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]

Graph theory studies networks of vertices connected by edges. Paths, cycles, and connectivity describe graph structure. Trees are connected acyclic graphs, fundamental for hierarchies and search. Planar graphs can be drawn without edge crossings. Graph coloring assigns labels satisfying constraints, modeling scheduling and resource allocation. Euler and Hamiltonian paths visit edges or vertices exactly once, connecting to classic optimization problems.

Confusing Euler and Hamilton paths. An Euler path visits every edge exactly once, while a Hamilton path visits every vertex exactly once. Euler paths have a simple degree-based characterisation (0 or 2 odd-degree vertices), but Hamilton path existence is NP-complete. Do not assume a graph with an Euler path also has a Hamilton path, or vice versa.

Misapplying Euler’s formula for planarity. Euler’s formula VE+F=2V - E + F = 2 applies only to connected planar graphs. Students often apply it to disconnected graphs or forget that faces include the unbounded outer face. Also, satisfying Euler’s formula is necessary but not sufficient for planarity; Kuratowski’s theorem provides the complete characterisation.

Incorrect chromatic polynomial evaluation. When computing P(G,k)P(G, k), students sometimes forget that the chromatic polynomial counts proper colourings (adjacent vertices must differ). Evaluating at k=2k = 2 gives 0 for non-bipartite graphs, which is a useful sanity check. Also, the deletion-contraction recurrence must be applied carefully to avoid double-counting.

  • [[1-algorithms/graph-algorithms]] - Graph algorithm implementations

  • [[1-discrete-mathematics/4_combinatorics]] - Counting graph structures

  • [[2-systems/networking]] - Network topology graphs

  • [[1-algorithms/data-structures]] - Graph data structures

  • Discrete Mathematics

  • Algorithm Implementation