Learning LabExplorable explanations
← All artifacts
Graphs

PageRank by Random Walk

One random surfer, clicking forever, ranks a whole web. Build a graph and watch a surfer's visit frequencies converge to the same PageRank vector that power iteration computes.

pagerankgraphsmarkov-chainpower-iterationrandom-walk
LiveInteractive · drag, toggle, run it
Graphs · Markov Chains

PageRank by Random Walk

PageRank scores a page by how often a surfer who clicks random links, and occasionally jumps to a page at random, ends up there. Two methods reach the same numbers: power iteration on the Google matrix, and a single surfer counting its own visits. Edit the graph and watch both views track each other.

5 nodes · 9 edges
ABCDE
Tap one node, then another, to add a directed edge. Tap an existing edge's endpoints to remove it. Node size and shade follow PageRank.

With probability d the surfer follows a random out-link; with probability 1 - d = 0.15 it teleports to a node picked uniformly at random. Teleportation is what makes the chain irreducible, so a unique ranking exists no matter how the links are wired. The classic web value is 0.85.

Power iteration
Start uniform, then repeatedly apply r ← G r. Each pass moves probability along the links until it stops changing.
A
20.00%
B
20.00%
C
20.00%
D
20.00%
E
20.00%
Iteration 0L1 change gap to exact 3.98e-1
Thin dark mark on each bar is the exact PageRank. The bars slide onto it within a few iterations.
Random surfer
One walker hops the real edges, teleporting with probability 1 - d. Its visit frequencies approach the exact ranks as steps pile up.
A
0.00%
B
0.00%
C
0.00%
D
0.00%
E
0.00%
Steps 0Teleports 0gap to exact
Press Run or +2000 to start counting visits. The bar chart fills in as the walk explores.
Why the two views agree

The Google matrix. Column j of M says where the surfer goes from node j: an even split across its out-links. The full operator is G = d M + (1 - d)/N, mixing those links with a uniform teleport. PageRank is the vector r that G leaves unchanged, the stationary distribution of the chain. Power iteration finds it by applying G over and over from any start.

Dangling nodes. A node with no out-links is a dangling node. A surfer landing there has nowhere to click, so its column is filled uniformly: from a dead end the walker restarts anywhere. Without that fix probability drains out of the system and the ranks no longer sum to one.

Walk equals matrix. By the ergodic theorem the long-run fraction of time the surfer spends at each node is exactly that stationary vector. So counting visits and powering up the matrix are two routes to the same ranking; the surfer is just a slow, noisy way to read off r.

Power iteration on G = d M + (1 - d)/N, with dangling columns spread uniformly. The surfer is a Monte Carlo sample of the same chain.