antifold

Theory

Graph Theory: A Practical Guide

Graphs are the language of connection. With a few simple ideas (paths, cuts, trees, and spectra), you can model networks in computation, physics, and learning.

Why graphs?

Graphs capture relations: who talks to whom, which states are reachable, which components touch. A graph $G=(V,E)$ has vertices $V$ and edges $E\subseteq V\times V$ (undirected if $(u,v)\in E \Rightarrow (v,u)\in E$). The adjacency matrix $A\in\{0,1\}^{|V|\times|V|}$ records edges; $A_{uv}=1$ if $u\to v$.

Matrix powers count walks: $(A^k)_{uv}$ is the number of length-$k$ walks from $u$ to $v$. Add edge weights to model costs, capacities, or affinities.

Local structure

Traversal and shortest paths

Breadth‑first search (BFS) explores in layers and yields shortest paths in unweighted graphs. For nonnegative weights, Dijkstra finds shortest paths; allowing negative edges, Bellman–Ford detects negative cycles and computes shortest distances when they don’t exist.

Spanning trees and cuts

A spanning tree touches all vertices with $|V|-1$ edges. With positive weights, minimum spanning trees (MSTs) can be found by Kruskal (sort edges; greedy add if no cycle) or Prim (grow a frontier). Cuts partition $V=S\cup \bar S$; their capacity is the sum of crossing edge weights. The max‑flow min‑cut theorem ties maximum flow from $s$ to $t$ to the minimum $s\!:\!t$ cut capacity.

Spectra: smoothness and clusters

The (combinatorial) Laplacian is $L=D-A$. For a vector $x\in\mathbb{R}^{|V|}$ defined on nodes, the Dirichlet energy

$$\mathcal{E}(x)=x^\top L x = \frac{1}{2}\sum_{(u,v)\in E} w_{uv}\,(x_u-x_v)^2$$

is small when adjacent nodes have similar values (often read as “smooth” over the graph). The smallest eigenvalue is $0$ with eigenvector $\mathbf{1}$. The second eigenvector (the Fiedler vector) approximately separates the graph into two balanced parts with a small cut; this underpins spectral clustering.

Random walks and diffusion

A random walk moves $u\to v$ with probability proportional to weight $w_{uv}$. Normalized operators (e.g., $L_{\text{rw}}=I-D^{-1}A$) govern diffusion and hitting times. Many ranking and centrality measures are walk‑based: degree centrality, PageRank, betweenness and closeness centrality.

Graphs in algorithms and learning

Planarity and Euler’s formula

Planar graphs satisfy $V - E + F = 2$ in any planar embedding (Euler characteristic). Non‑planarity is characterized by subdivisions of $K_5$ or $K_{3,3}$ (Kuratowski). These constraints inform routing, VLSI, and visualization.

A compact toolbox

Interactive: BFS shortest paths

Click a node to pick the source. Colors show layers (distance) from the source; thin arrows point along the BFS tree.
BFS explores the frontier layer by layer. If $A$ is the adjacency matrix, the set of nodes at distance $k$ from $s$ appears in the support of $A^k \mathbf{e}_s$ that wasn’t seen earlier. Distances $d(v)$ and parents $\pi(v)$ form a shortest‑path tree.
Frontier size: Visited:

Interactive: Kruskal’s MST

Edges are weighted (length on screen). Kruskal sorts edges by weight and adds one if it doesn’t create a cycle (via disjoint sets). Green = in MST, gray = unused, amber = next candidate.
MST minimizes $\sum_{(u,v)\in T} w_{uv}$ subject to $T$ being a tree. Greedy works because cuts have a safe minimum edge (cut property). We show $\text{find}$/$\text{union}$ sets to explain cycle tests.
Total weight: 0Edges chosen: 0

Interactive: Laplacian diffusion

Click nodes to toggle hot/cold seeds (fixed values). Others evolve by $x \leftarrow x - \alpha L x$ which decreases $\mathcal E(x)=x^\top L x$ (smooths values along edges).
Here $L=D-A$ with $D_{uu}=\deg(u)$. Fixed seeds implement Dirichlet conditions. A small step $\alpha$ performs gradient descent on $\mathcal E(x)$; colors show $x_u$ (blue→white→red).
Connections

How this article plugs into other pieces on the site: