🕸️ Network Resilience
Scale-Free Networks · Targeted Hub Attack · Random Node Failure · Giant Component · Percolation
Scale-Free Networks · Targeted Hub Attack · Random Node Failure · Giant Component · Percolation
This simulation contrasts how two classes of network survive node removal. It builds either a Barabási–Albert scale-free graph, grown by preferential attachment (each new node links to m=2 existing nodes with probability proportional to their degree), or an Erdős–Rényi random graph where every pair of nodes connects independently with probability p ≈ 2.5·ln(N)/N. After each removal it runs a breadth-first search to recompute connected components and the size of the giant component.
The Nodes slider sets N (20–150), and tabs switch the network type and the attack mode. In targeted mode the highest-degree surviving node (a hub) is removed first; in random mode a uniformly random node is removed. The removal-speed slider controls nodes removed per frame, while Attack, Rebuild and Step drive the process. This asymmetry — robust to random failure, fragile to hub attack — explains the resilience of the internet, power grids and protein interaction networks.
What does this simulation actually show?
It removes nodes from a network one at a time and tracks how connectivity collapses. After every removal it measures the giant component — the largest set of still-connected nodes. You can watch a scale-free network shatter under a targeted hub attack while shrugging off random failures of the same size.
What is a scale-free network?
A scale-free network has a power-law degree distribution: most nodes have few links, but a handful of hubs have very many. This page generates one with the Barabási–Albert model, where each new node attaches preferentially to nodes that are already well connected, so the rich get richer.
How is the Erdős–Rényi network different?
In the Erdős–Rényi random graph every possible edge exists with the same probability p, giving a Poisson degree distribution with no dominant hubs. Because there are no critical hubs to single out, targeted and random attacks produce roughly similar damage, unlike the scale-free case.
The giant component is the largest connected cluster of surviving nodes. Its fraction (size divided by the number of alive nodes) measures how much of the network can still communicate. When that fraction collapses toward zero, the network has fragmented into isolated islands and effectively stopped functioning.
In targeted mode the simulation scans all surviving nodes and removes the one with the highest current degree — the biggest remaining hub. Removing a hub severs many edges at once, so its neighbours can splinter into separate fragments far faster than removing an ordinary node would.
After a node is deleted, the code runs a breadth-first search over the remaining alive nodes and edges, labelling each with a component ID. It then counts the nodes in each component to find the largest one. This BFS is the standard way to identify connected components in an undirected graph.
Total and removed nodes track N and how many you have deleted. Giant component shows its raw size, and GC fraction shows it as a percentage of survivors. Components counts how many separate clusters exist, and Max degree (hub) reports the largest degree still present — useful for watching hubs disappear under attack.
It is a faithful qualitative model of percolation on real networks and reproduces the famous robust-yet-fragile behaviour reported by Albert, Jeong and Barabási in 2000. With only up to 150 nodes it is a teaching-scale illustration rather than a research simulation, but the mechanisms — preferential attachment and degree-based attack — are the genuine ones.
Because most nodes have low degree, a random failure almost always hits an unimportant node and barely dents connectivity. But the same network depends on a few hubs to tie everything together, so an attacker who knows which nodes are hubs can dismantle it with very few, well-chosen removals. This is the robust-yet-fragile trade-off.
The internet's router topology, airline route maps, power grids, financial networks and cellular protein interactions are all roughly scale-free. The lesson is double-edged: such systems tolerate random faults gracefully, but protecting or attacking just their few hubs has an outsized effect — which guides everything from cybersecurity to epidemic control.