This simulation builds the Watts-Strogatz model. It starts from a regular ring lattice in which each of N nodes connects to its k nearest neighbours, then rewires each edge with probability p to a randomly chosen distant node. As p increases, the network is measured by two quantities: the average clustering coefficient C, computed as the fraction of a node's neighbours that are themselves linked, and the average shortest path length L, found by breadth-first search between node pairs.
The N, k and p sliders set the lattice size, local connectivity and rewiring fraction, while the Rewire and Reset buttons regenerate the graph. The chart tracks the ratios C(p)/C0 and L(p)/L0 against the unrewired lattice. The key insight is that a handful of long-range shortcuts collapse path length while clustering stays high, producing the "small-world" regime. This explains six degrees of separation in social, neural and infrastructure networks.
What is a small-world network?
A small-world network is a graph that combines high local clustering, like a regular lattice, with short average path lengths between any two nodes, like a random graph. Watts and Strogatz introduced it in 1998 to explain why real networks such as friendships or power grids are both locally cliquey and globally well connected.
How does the Watts-Strogatz rewiring work?
The model begins with a ring lattice where each node links to its k nearest neighbours. It then visits every edge and, with probability p, reconnects one end to a random node elsewhere in the ring, avoiding self-loops and duplicate links. At p = 0 nothing changes; at p = 1 nearly all edges become random shortcuts.
What do the N, k and p sliders control?
N sets the number of nodes (10 to 80), k sets how many nearest neighbours each node starts with (2 to 10, always even), and p sets the rewiring probability from 0 to 1. Changing N or k rebuilds the lattice, while moving p re-runs the rewiring and recomputes the statistics live.
The clustering coefficient of a node is the fraction of its neighbour pairs that are also directly connected, computed as 2 times the number of links among neighbours divided by k times k minus one. C is the average of this over all nodes, ranging from 0 to 1. High C means your friends tend to know each other.
L is the mean number of edges on the shortest route between node pairs, found by running breadth-first search from each source node. For speed the simulation samples up to 20 source nodes rather than all of them, which gives an accurate estimate of L without computing every pair on larger graphs.
At small but non-zero p, just a few long-range shortcuts dramatically shorten the average path length L while the local clustering C barely falls. The network keeps its tight-knit neighbourhoods yet becomes globally navigable in very few steps. The badge flags this regime when p is roughly between 0.01 and 0.3.
They are the clustering and path length divided by their values for the original unrewired lattice (p = 0). Plotting these normalised ratios reveals the signature small-world dip: L/L0 plunges quickly as p rises, while C/C0 stays near one until much higher p, leaving a wide gap between the two curves.
Yes, it follows the standard Watts-Strogatz procedure: a k-regular ring lattice rewired edge by edge with probability p. The clustering and BFS path-length formulas are exact, though path length uses a random sample of sources for performance, so values fluctuate slightly between runs of the same settings.
It is the popular idea that any two people are connected through a chain of about six acquaintances. Small-world structure makes this plausible: a sparse social network with only modest random long-range ties has an average path length that grows very slowly, roughly logarithmically, with population size.
They are found across many systems, including neural wiring in the brain, the power grid, the actor collaboration graph, the World Wide Web and protein interaction networks. The structure supports fast information or signal spreading while preserving robust local communities, which is why it recurs so widely in nature and technology.