Lab-in-a-Tab

Graph Theory & Networks

Six handshakes separate any two people on Earth. The internet, your brain, and a virus outbreak all obey the same hidden mathematics.

▶ Run the interactive simulation
NetworksTopologyConnections

Everything is connected - but how?

Junior level — plain language, no maths

Suppose you want to get a message to a famous stranger you've never met - a head of state, a film star. You tell a friend, who tells one of their friends, who tells one of theirs. How many hops until you reach anyone on the planet? In 1967 Stanley Milgram ran the experiment with posted letters and got a startling answer: about six. Six degrees of separation, between you and everyone alive.

That's the quiet power of networks. A network - mathematicians call it a graph - is nothing more than a set of nodes (things) joined by edges (links). Your friendships are a graph. So are cities wired by roads, web pages stitched together by hyperlinks, neurons laced through your brain, proteins reacting inside a cell. Same skeleton, wildly different flesh.

The big surprise of the last fifty years is that these utterly different networks share the same hidden architecture. Crack that architecture and you can predict how an epidemic spreads, how a blackout cascades across a power grid, how one shuttered airport snarls global travel, how a rumour goes viral. In the simulation below, watch information ripple through a network - and notice how a single well-connected hub can change everything.

Things worth knowing

  • The entire World Wide Web has an average path length of just 19 clicks between any two pages - out of billions of possible routes.
  • COVID-19 spread so fast partly because air travel creates a "small-world" network - a single superspreader event in one city reaches every continent within days.
  • The 2003 Northeast blackout cascaded from a single Ohio power line failure to cut power for 55 million people in 8 states - pure network vulnerability.

Small worlds, scale-free networks, and Euler's bridges

Student level — the core equations

Graph theory was born in 1736, when Leonhard Euler took on the bridges of Königsberg: could you stroll through the city crossing each of its seven bridges exactly once? Euler proved you couldn't - and his argument threw the map away entirely, keeping only what connects to what. Such a walk exists precisely when the graph has either 0 or 2 vertices of odd degree, and nothing else matters. Discarding geometry and keeping pure connectivity founded a whole branch of mathematics.

A graph \(G = (V, E)\) is just a set of vertices \(V\) and edges \(E\). The degree \(d(v)\) counts a vertex's neighbours, and the degree distribution \(P(k)\) - the chance a random node has \(k\) links - turns out to be the network's fingerprint. Sprinkle edges at random (the Erdős–Rényi model) and you get a tidy Poisson distribution and a sharp phase transition: cross \(p = 1/n\) and a giant connected component snaps into being. But real networks look nothing like random ones. They are small worlds - tightly clustered yet only a few hops across (Watts–Strogatz, 1998) - and scale-free, with a heavy-tailed \(P(k) \sim k^{-\gamma}\) (Barabási–Albert, 1999) that emerges whenever newcomers prefer to link to the already-popular.

That scale-free shape carries a startling double edge. These networks are robust to random failure - nearly every node is a minor one, so a random knockout rarely touches a hub - yet fragile to a targeted strike: pull out the handful of biggest hubs and the whole thing fractures. It's why the internet shrugs off router crashes but dreads a coordinated attack, and why vaccinating the few super-connectors halts an outbreak far more efficiently than vaccinating people at random.

Key formulas

Handshaking lemma\(\sum_v d(v) = 2|E|\)
Eulerian path\(\text{exists} \iff 0 \text{ or } 2 \text{ odd-degree vertices}\)
Clustering coefficient\(C(v) = \dfrac{2\,e_v}{d(v)\,(d(v)-1)}\)e_v = edges among neighbours
Average path length\(L = \dfrac{1}{n^2}\sum_{u,v} d(u,v)\)
Scale-free degrees\(P(k) \sim k^{-\gamma},\quad 2 < \gamma < 3\)
ER phase transition\(p_c = \dfrac{1}{n}\)giant component emerges

Things worth knowing

  • The protein-interaction network of yeast is scale-free with γ ≈ 2.4 - removing the top 1% of hub proteins kills the cell; removing 99% of non-hubs does not.
  • Wikipedia's hyperlink network has average path length ~3.5 - you can reach almost any article from any other in 4 clicks.
  • The Barabási-Albert preferential attachment model generates scale-free networks with γ = 3 - matching the exponent measured in the World Wide Web.

Spectral graph theory, random walks, and network epidemics

Scholar level — full mathematical depth

01The Laplacian: a matrix that remembers the shape

Strip a network down to numbers and its whole structure lives in the graph Laplacian \(L = D - A\), built from the degree matrix \(D\) and the adjacency matrix \(A\). Diagonalise it and the eigenvalues \(0 = \lambda_1 \le \lambda_2 \le \dots \le \lambda_n\) read out the network's geometry without your ever drawing it. The number of zero eigenvalues counts the connected pieces; the gaps between the rest encode bottlenecks, symmetries, and how heat or rumour would diffuse across the graph. Spectral graph theory is the surprising claim that you really can hear the shape of a network.

02The Fiedler value: how connected, really?

The second eigenvalue \(\lambda_2\) - Fiedler's algebraic connectivity - is the one to watch. It sits just above zero when a graph is barely held together and climbs as the graph knits tighter. Cheeger's inequality makes that intuition exact, trapping the true bottleneck \(h(G)\) (the cheapest cut relative to its size) between two functions of the spectrum: \(\dfrac{\lambda_2}{2} \le h(G) \le \sqrt{2\lambda_2}\). A small \(\lambda_2\) guarantees some sparse cut exists; a large one certifies the network has no weak seam to tear along.

03Spectral clustering: finding the communities

That same Fiedler eigenvector earns its keep in practice. Sort the nodes by the sign of their entry in it and the graph tends to split along its most natural seam - the heart of spectral clustering, the algorithm underneath a great deal of modern community detection, image segmentation and recommendation. What looks like an abstract eigenvalue problem turns out to be the cleanest known way to ask, "which parts of this network actually belong together?"

04Random walks, mixing and PageRank

Set a token wandering the graph, hopping to a random neighbour at each step - a random walk with transition matrix \(P = D^{-1}A\). It settles into a stationary distribution \(\pi(v) = d(v)/2|E|\), purely proportional to degree, and the time it needs to forget where it began - the mixing time - scales as \(\tau_{\text{mix}} \sim \log n / \lambda_2\): well-knit "expander" graphs mix in a blink, bottlenecked ones crawl. Bolt on a small chance of teleporting anywhere and you have PageRank, the random walk whose stationary distribution Google first used to rank the web.

05Epidemics on networks: the vanishing threshold

Run an SIR contagion - susceptible, infected, recovered - across a graph and a sharp threshold appears: the outbreak only catches when \(\beta/\mu > 1/\lambda_{\max}(A)\), governed by the largest eigenvalue of the adjacency matrix. Here scale-free topology springs its nastiest trick. For \(\gamma \le 3\), \(\lambda_{\max}\) grows without bound as the network grows, so the threshold slides all the way to zero: on a large scale-free network an epidemic spreads no matter how feeble the transmission. That is the deep reason computer viruses and online misinformation are so stubborn - the hubs hand them a foothold for free.

06The hard problems hiding in plain graphs

For all this elegance, some of the simplest-sounding graph questions are among the hardest known. Asking whether a graph has a Hamiltonian path - a route visiting every node exactly once - is NP-complete, and an efficient algorithm for it would topple thousands of other problems at a stroke and settle P versus NP, the deepest open question in computer science. Graphs are where abstract connectivity slams into the brick wall of computational hardness - which is the room next door.

Key formulas

Graph Laplacian\(L = D - A\)
Spectrum\(0 = \lambda_1 \le \lambda_2 \le \dots \le \lambda_n\)
Cheeger inequality\(\dfrac{\lambda_2}{2} \le h(G) \le \sqrt{2\lambda_2}\)
Random-walk mixing\(\tau_{\text{mix}} \sim \dfrac{\log n}{\lambda_2}\)
SIR epidemic threshold\(\dfrac{\beta}{\mu} > \dfrac{1}{\lambda_{\max}(A)}\)
Scale-free limit\(\lambda_{\max}(A) \to \infty \;(\gamma \le 3) \;\Rightarrow\; \text{threshold} \to 0\)

Things worth knowing

  • The spectral gap λ₂ of the Petersen graph equals 2 - it is the smallest 3-regular expander, which is why it appears in so many extremal graph theory results.
  • The epidemic threshold on the internet (scale-free, γ≈2.1) is effectively zero - explaining why computer viruses persist indefinitely at any transmission rate.
  • The P vs NP problem is equivalent to asking whether the Hamiltonian path problem (does a graph have a path visiting every node once?) can be solved efficiently - still unsolved.

Sources

Full article on Wikipedia ↗