Sub topic 4
Why Links Work as Votes: The PageRank Idea
This chapter assumes you can read simple HTML, know that a backlink is a link from one site to another, and know that search engines crawl pages and store the links they find. It covers the idea that turned those stored links into a ranking signal.
From links to votes
A search engine that only reads page text can be fooled by anyone who repeats a keyword often enough. Links are harder to fake because they are placed by other people. When a site links to your page, it makes a small statement that the page is worth visiting.
PageRank, introduced by Google's founders, formalizes this. Each link is treated as a vote for its target. Two rules make the model work:
- A page with more incoming links usually has more votes.
- A vote from an important page counts for more than a vote from an unimportant one.
The second rule makes the definition circular: a page is important if important pages link to it. The calculation resolves this by repeating a simple step until the scores stop changing.
The random surfer
PageRank is often explained with a random surfer. The surfer starts on a random page and keeps clicking a random link on the current page. Now and then, the surfer gets bored and jumps to a random page instead. A page's score is the long-run share of time the surfer spends on it.
Two details follow from this picture:
- Splitting. A page divides its score among its outgoing links. A page with 2 links passes half its score along each. A page with 200 links passes a much smaller share along each.
- Damping. The damping factor (commonly 0.85) is the chance that the surfer follows a link rather than jumping away. The remaining 0.15 is spread evenly over all pages. This keeps every page above zero and stops score from getting trapped in closed loops.
Computing it
The toy implementation below applies the idea directly. Each round, every page sends its current score, divided equally, to the pages it links to. Then the damping term is added.
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
web = {
"A": ["B", "C"],
"B": ["C"],
"C": ["A"],
"D": ["C"],
}
for page, score in sorted(pagerank(web).items(), key=lambda item: -item[1]):
print(page, round(score, 3))Run it and read the output in this order:
- C ranks first. It receives links from A, B, and D.
- A ranks second. It has only one incoming link, but that link comes from C, the highest-scoring page. This shows the second rule at work: A beats B even though both are linked by a single page, because C's vote is worth more.
- D ranks last. Nothing links to it, so it only receives the damping share.
The scores sum to 1, so they read as probabilities. A page's score depends on the whole graph. Changing one link can shift every score a little.
Common errors in the mental model
Several misreadings come up often:
- Counting links instead of weighing them. Ten links from obscure pages can be worth less than one link from a respected page. Raw counts are a weak proxy.
- Ignoring the split. A link from a page with hundreds of outgoing links passes along only a small slice of that page's score.
- Treating PageRank as the whole algorithm. It is one input among many. Later chapters place it next to relevance, content quality, and other signals.
- Believing the public number is current. Google retired the public PageRank toolbar score. Third-party "authority" metrics are estimates built by other companies, not Google's values.
- Assuming every link counts. Links marked
nofollow,sponsored, orugc, and links identified as spam, may pass little or no value. The later chapters on link attributes and spam policies explain this.
Why this matters for practice
The model explains why backlinks affect rankings in the first place. A link transfers some of the linking page's standing to the target, and that standing was itself earned through links. This is also why manipulating links became a problem: if votes raise rankings, people have a reason to manufacture votes. Search engines respond with spam policies, which a later chapter covers.
Exercise
In the toy graph, page A links to B and C, and page B links only to C. Page A's score is 0.4. Ignoring damping, how much score does A send to each of B and C in one round? Why would a link from a page with 40 outgoing links be worth less than a link from A?
Show answer
A splits its score equally among its 2 outgoing links, so it sends 0.2 to B and 0.2 to C. A page with 40 outgoing links divides its score 40 ways, so each link carries only a small share, while A's links each carry half of A's score.
Exercise
Why does the PageRank calculation include a damping factor of 0.85?
Show answer
It models a surfer who follows a link 85% of the time and jumps to a random page 15% of the time. This gives every page a minimum score and stops score from becoming trapped in groups of pages that only link to each other.