Graph Theory | Computer Science
5.1 Definitions
Section titled “5.1 Definitions”A graph consists of a set of vertices and a set of edges .
- Simple graph: no loops, no multiple edges.
- Directed graph (digraph): edges have direction.
- Weighted graph: edges have weights.
The degree of a vertex , Is the number of edges incident to .
Theorem 5.1 (Handshaking Lemma). .
Proof. Each edge contributes 1 to the degree of each of its two endpoints.
Corollary 5.2. The number of vertices of odd degree is even.
5.2 Paths, Cycles, and Connectivity
Section titled “5.2 Paths, Cycles, and Connectivity”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 vertices and more than edges is connected.
5.3 Trees
Section titled “5.3 Trees”A tree is a connected acyclic graph. A forest is a disjoint union of trees.
Theorem 5.4. For a graph with vertices, the following are equivalent:
- is a tree.
- is connected and has edges.
- is acyclic and has edges.
- Between any two vertices, there is exactly one path.
Cayley”s Formula. The number of labelled trees on vertices is .
5.4 Planarity
Section titled “5.4 Planarity”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 vertices, edges, and faces:
Proof sketch. Build the graph edge by edge. Starting from a single vertex (, , ), The quantity is preserved when adding an edge: if the edge connects two components, and each increase by 1; if it splits a face, and each increase by 1.
Corollary 5.6. For a simple planar graph with : .
Proof. Every face has at least 3 edges on its boundary, and every edge borders at most 2 faces, So . By Euler’s formula, Giving I.e., .
Corollary 5.7. and are not planar.
Proof. has , But . For , , . Since has no triangles, every face has at least 4 edges, giving So . But gives . Contradiction.
Theorem 5.8 (Kuratowski’s Theorem). A graph is planar if and only if it does not contain a Subdivision of or as a subgraph.
A subdivision of an edge replaces with a path —— through a new vertex . A graph is a subdivision of if can be obtained from by subdividing edges.
Worked Example. Show that is not planar using Euler’s formula.
Solution
has vertices and 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 I.e., .
But Euler’s formula gives . Since No planar embedding Exists.
5.5 Graph Colouring
Section titled “5.5 Graph Colouring”A proper -colouring assigns one of colours to each vertex such that adjacent vertices have Different colours. The chromatic number is the minimum for which a proper -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). where is the Maximum degree.
Theorem 5.12 (Brooks’ Theorem). If is connected and is neither a complete graph nor an odd Cycle, then .
Chromatic polynomial. The chromatic polynomial counts the number of proper -colourings of .
Theorem 5.13. is a polynomial in .
Deletion-contraction recurrence. For any edge of :
Where is with edge deleted, and is with contracted (its endpoints Merged).
Worked Example. Find the chromatic polynomial of (the 4-cycle).
Solution
Label the vertices of as with edges , , , .
Pick edge .
is a path on 4 vertices (a tree): .
merges and Yielding (triangle): .
Therefore .
Checking: (two 2-colourings: alternating), and .
Worked Example. Find and .
Solution
(complete graph on vertices): every pair of vertices is adjacent, so all vertices must Receive distinct colours. Hence .
(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 (for ).
Worked Example. Find the chromatic polynomial of (triangle).
Solution
Choose a colour for vertex 1: choices. Choose a colour for vertex 2 (different from vertex 1): choices. Choose a colour for vertex 3 (different from both): choices.
.
Checking: (not 2-colourable, as expected). .
5.6 Euler and Hamilton Paths
Section titled “5.6 Euler and Hamilton Paths”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 . If uses all edges, we are done. Otherwise, remove ‘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 at shared Vertices yields an Euler circuit of the full graph.
Worked Example. Does have an Euler circuit? An Euler path?
Solution
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, 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 is a simple graph with vertices and for every vertex, then has a Hamilton circuit.
Theorem 5.16 (Ore’s Theorem). If is a simple graph with vertices and for every pair of non-adjacent vertices Then has a Hamilton Circuit.
Note that Dirac’s theorem is a corollary of Ore’s theorem.
Worked Example. Does have a Hamilton circuit?
Solution
has 5 vertices. A Hamilton circuit must visit all 5 vertices and return. Label the Partitions as and . Any cycle in a bipartite graph alternates Between the two partitions. A Hamilton cycle would alternate between and Requiring . But So no Hamilton circuit exists.
However, does have Hamilton paths (e.g., — wait, this doesn’t Alternate properly). Actually, in edges only exist between and . A path must alternate or . A Hamilton path visits all 5 vertices, so it has the Form (length 5, starting and ending in ) or (length 5, starting And ending in ). The first requires 3 vertices from But . The second requires 3 Vertices from And . So a Hamilton path exists: e.g., .
Worked Example. Let have vertices and edges . Does have an Euler circuit or Euler path?
Solution
Degrees: , , , , . Two vertices (1 and 5) have odd degree. Since exactly two vertices have odd degree, has an Euler Path (starting at 1, ending at 5) but no Euler circuit.
One Euler path: . 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]Intuition
Section titled “Intuition”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.
Common Mistakes
Section titled “Common Mistakes”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 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 , students sometimes forget that the chromatic polynomial counts proper colourings (adjacent vertices must differ). Evaluating at 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.
Cross-References
Section titled “Cross-References”[[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