Sub topic 4
Why links work as votes: the PageRank idea
This chapter explains the reasoning behind treating links as votes. It then builds a small PageRank calculation so you can see the mechanism work. It assumes you can read simple HTML, know that search engines crawl and index pages, and know what a backlink is from the earlier chapters. It also assumes you can read short Python.
The problem links solved
Early search engines ranked pages mostly by the words on them. A page that repeated "cheap flights" many times scored well. Anyone could edit their own page, so this was easy to manipulate. The engines needed a signal that the page's author could not set directly.
Links offered one. When site A links to page B, the author of A made a choice about what to point readers toward. That choice is evidence that B is worth a visit. Collecting that evidence across billions of pages gives a rough, crowd-sourced opinion of what is important.
Academic citations work the same way. A paper cited by many other papers is probably influential. A citation from a respected paper counts for more than a citation from an obscure one. PageRank, the algorithm Larry Page and Sergey Brin described at Stanford in the late 1990s and used in Google's early ranking, applies this reasoning to web pages.
The vote metaphor, and where it stops
The simple version is: a link is a vote, and pages with more votes rank higher. That version is wrong in three ways that matter in practice.
- Votes are not equal. A vote from an important page carries more weight than a vote from an unimportant one.
- Votes are shared. A page splits its influence among all the pages it links to. A page with two outgoing links gives each about half of what it passes on. A page with two hundred gives each about a hundredth.
- Importance is circular. A page is important if important pages link to it, but those pages are important for the same reason. PageRank resolves this by calculating all the scores together, repeating the calculation until they stop changing.
The random surfer model
PageRank is usually explained with a thought experiment. Imagine a person browsing at random. They land on a page and pick one of its links with equal probability. Most of the time they follow it. Some of the time, with probability 1 - d, they get bored and jump to a random page anywhere on the web. The value d is the damping factor, commonly 0.85.
A page's PageRank is the long-run fraction of time this surfer spends on it. Pages with many links from frequently visited pages are visited often, so they score high. The random jump keeps the calculation stable. Without it, the surfer could get stuck in a loop of pages that link only to each other.
The update rule for one page is:
PR(page) = (1 - d) / N + d * sum( PR(source) / outlinks(source) )N is the number of pages. The sum runs over every page source that links to page. Each source contributes its own score divided by its number of outgoing links, which is exactly the vote-sharing from the list above.
A worked example
The following code implements the update rule and applies it to two small webs. In the second web, page C also links to page D. Nothing else changes.
def pagerank(graph, damping=0.85, iterations=50):
"""Toy PageRank. Assumes every page has at least one outgoing link."""
n = len(graph)
ranks = {page: 1 / n for page in graph}
for _ in range(iterations):
new_ranks = {page: (1 - damping) / n for page in graph}
for page, outlinks in graph.items():
share = ranks[page] / len(outlinks)
for target in outlinks:
new_ranks[target] += damping * share
ranks = new_ranks
return ranks
before = {
"A": ["B", "C"],
"B": ["C"],
"C": ["A"],
"D": ["C"],
}
after = {
"A": ["B", "C"],
"B": ["C"],
"C": ["A", "D"],
"D": ["C"],
}
for label, web in (("before", before), ("after", after)):
print(label)
for page, score in sorted(pagerank(web).items(), key=lambda item: -item[1]):
print(" ", page, round(score, 3))Running it prints:
before
C 0.394
A 0.373
B 0.196
D 0.037
after
C 0.429
A 0.22
D 0.22
B 0.131Three things stand out.
- C wins in both runs. It receives links from A, B, and D, and A is itself well linked. C collects the most inbound votes.
- D scores 0.037 in the first web. That equals
(1 - 0.85) / 4, the floor every page gets from the random jump. D links out, but nothing links to D, so it receives nothing else. - One link moves D from 0.037 to 0.22. The link came from C, the highest-scoring page, and C had only one other outgoing link, so it passed on half of its weight. A link from the best-placed page with few other links is worth far more than many links from pages that nobody links to.
The scores in each run sum to 1, because they describe a probability distribution over pages. They are not absolute measures of quality. Adding a link moves rank around the graph. It does not create rank.
How the calculation is carried out
The code uses power iteration. It starts every page at an equal score, applies the update rule to all pages at once, and repeats. Each round spreads rank one step further through the graph. After enough rounds the scores stop changing. The damping factor guarantees this happens. With d = 0.85, the error shrinks roughly by a factor of 0.85 per round, so fifty rounds leave an error far below the three decimal places printed.
Real search engines cannot hold the web in a Python dictionary. They run the same idea as a distributed computation over a graph of billions of nodes. The principle is unchanged: each page's score is shared out along its links, and the process repeats until it settles.
Edge cases the toy version ignores
The code's docstring says it assumes every page has an outgoing link. Real graphs break that assumption in several ways.
| Situation | What goes wrong | Usual remedy |
|---|---|---|
| Dangling page with no outgoing links | Its rank has nowhere to go, so total rank leaks away and the code would divide by zero | Spread a dangling page's rank evenly across all pages |
| Closed cluster of pages linking only to each other | Rank flows in but never out, so the cluster hoards it | The random jump moves some rank back out every round |
| Self-links and duplicate links | A page could inflate its own share | Remove or discount them when building the graph |
| Links marked `nofollow`, `sponsored`, or `ugc` | The link may not pass rank, or may pass less | Treat the attribute as a hint when building the graph |
The last row connects this chapter to link attributes. Google has described nofollow, sponsored, and ugc as hints. It may use them as signals when deciding how to treat a link, so they do not guarantee that a link passes nothing.
Why this makes links hard to fake
The sharing rule is what gives links their value as evidence. Two properties follow from it.
Cost of acquiring weight. To raise your own score, you need links from pages that already have score. Those pages are controlled by other people who have no reason to hand over their weight and who dilute it across their other links. Creating thousands of new pages that link to you does not help much, because each new page starts with only the random-jump floor. In the example, D sat at 0.037 with a link out and nothing coming in.
Circular structures are discounted. Two sites that link only to each other trade rank back and forth without gaining any from outside. The next chapters cover how search engines detect and penalize this pattern. The reasoning begins here: rank has to enter a cluster from the wider web to mean anything.
None of this makes manipulation impossible, which is why link spam is an ongoing problem with its own policies. But the design means that cheap links from nowhere carry little weight, and that is the reason legitimate, editorial links remain valuable.
From PageRank to what you see in practice
PageRank scores a page's importance from the link graph alone, independent of any search query. Three practical points follow.
- It is a page-level measure. Links point to specific URLs. A link to your home page does not automatically help a deep product page, although internal links can pass some weight onward.
- It says nothing about relevance to a query. A highly linked page about gardening should not rank for a question about tax law. Ranking combines link-based importance with many other signals, covered in a later chapter.
- The public score is gone. Google removed the Toolbar PageRank display in 2016. Third-party metrics such as Domain Rating or Domain Authority are estimates built by other companies. They are not Google's numbers, and a high one does not guarantee a ranking.
Common mistakes
- Counting links instead of weighing them. Fifty links from low-value pages may do less than one editorial link from a respected, relevant page.
- Ignoring outgoing links on the linking page. A link on a page with two outbound links passes more than the same link on a page with two hundred.
- Treating a score as a ranking. A high link-based score does not place a page first. It is one input among many.
- Assuming every link passes weight. Attributes, link placement, and spam filters all affect whether and how much a link counts.
Exercises
Exercise
In the before web, page D links to C but scores only 0.037, the lowest in the graph. Why is D's score so low, and what is the smallest change that raised it in the after web?
Show answer
Nothing links to D, so it receives only the random-jump share (1 - 0.85) / 4 = 0.0375 and no inbound votes. Adding a single link from C to D raised it, because C is the highest-scoring page and passes half of its weight to D. This gives D about 0.22.
Exercise
Page X has a score of 0.30 and links to 3 pages. Page Y has a score of 0.30 and links to 30 pages. Using damping 0.85, how much does each page contribute to a page it links to, and what does that imply about where you would want a backlink?
Show answer
X contributes 0.85 0.30 / 3 = 0.085 per target. Y contributes 0.85 0.30 / 30 = 0.0085 per target, one tenth as much. All else equal, you would prefer a link from X, because its vote is shared among fewer pages.
Exercise
Why does the PageRank model include a random jump with probability 1 - d, and what would go wrong without it?
Show answer
The random jump gives every page a minimum score and lets rank escape closed clusters of pages that link only to each other. Without it, such clusters would absorb rank and never release it, and the iteration might not settle on a unique, sensible answer.