PageRank Web Graph Ranking
The algorithm that launched Google — ranking pages by link importance
What is it?
Imagine the internet as a giant map where every web page points to others (hyperlinks). Some pages are more important because many other important pages link to them. PageRank is the algorithm that measures this importance.
In this cipher, a small web graph is given. Each page has a label (an ASCII code). You run PageRank to find which pages are most important — the top-ranked pages in order spell the answer.
Concrete Example
Page 0 → [1, 2] Label: 72 ('H')
Page 1 → [2] Label: 69 ('E')
Page 2 → [3] Label: 76 ('L')
Page 3 → [0] Label: 76 ('L')
Page 4 → [0, 1] Label: 79 ('O')
After PageRank (damping=0.85, 50 iterations):
Rank order: Pages 0 > 2 > 3 > 1 > 4
Top labels: 72, 76, 76, 69, 79 → HELLO
How It Works
- A random web graph of 4-10 pages is generated with directed links
- Each page's label code is an ASCII character from the answer
- PageRank iteratively computes importance scores
- PR(p) = (1-d)/N + d × Σ(PR(q)/out(q) for every q that links to p)
- Pages are sorted by rank descending, their labels form the answer
Step-by-Step Solving
def pagerank(links, damping=0.85, iterations=50):
n = len(links)
rank = [1.0/n] * n
for _ in range(iterations):
new_rank = [(1-damping)/n] * n
for i in range(n):
if links[i]:
share = rank[i] / len(links[i])
for j in links[i]:
new_rank[j] += damping * share
rank = new_rank
return rank
pages = [...] # from puzzle data
ranks = pagerank([p['links_to'] for p in pages])
order = sorted(range(len(ranks)), key=lambda i: ranks[i], reverse=True)
answer = ''.join(chr(pages[i]['label_code']) for i in order[:5])
print(answer)
Difficulty Table
| Level | What Happens | Time Estimate |
|---|---|---|
| 1 | 4 pages, clear ranking | <10s |
| 3-5 | 6-8 pages, complex link structure | 20-40s |
| 6-7 | 10+ pages, near-dead-ends and rank sinks | 1-3m |
Real-World Applications
- Google Search: Larry Page and Sergey Brin created PageRank at Stanford — it was the breakthrough that made Google vastly better than AltaVista and Yahoo
- Recommendation systems: Amazon and Netflix use graph ranking to recommend products and movies
- Social network analysis: Finding influential people on Twitter/LinkedIn uses variants of PageRank
- Citation analysis: Scientific papers are ranked by how many important papers cite them (Eigenfactor)
- Bioinformatics: Ranking genes by importance in protein interaction networks uses PageRank-like algorithms