Why PageRank? • Quick Try • Visual Proofs • The Math • Benchmark • How to Run • Files
Back in the late 1990s, early search engines like Yahoo and AltaVista ranked web pages by counting keywords. If you typed "running shoes", the engine simply looked for pages that had the phrase "running shoes" repeated the most times.
Naturally, people gamed this within days. Spammers hid the word "shoes" 10,000 times in tiny white font on a white background, instantly jumping to the top of search results. Keyword counting was completely broken.
Larry Page and Sergey Brin tackled this with a smart insight:
A hyperlink is a vote of confidence.
If website A links to website B, website A is vouching for website B. But not all votes are equal — a link from CNN carries infinitely more weight than a link from an unknown personal blog.
Because important pages give important votes, and you need to know who is important to calculate importance, this creates a circular dependency. You cannot solve that with simple counting — but you can solve it cleanly using Linear Algebra (Markov Chains and Eigenvectors).
This project implements that exact mathematics:
- A Python numerical script (
pagerank_demo.py) that builds each matrix step-by-step and solves for the steady-state eigenvector. - A browser simulator (
index.html) where you can drag nodes around, draw links, and watch PageRank update in real time.
Want to test it right now without installing anything?
Tip
Just download this repo, unzip it, and double-click index.html in your browser. It runs locally with zero dependencies (pure HTML5 Canvas and Vanilla JS).
If you want to run the Python math engine:
git clone https://github.com/Vanshdev3/Google-PageRank.git
cd Google-PageRank
pip install numpy
python pagerank_demo.pyBoth the terminal solver and the interactive web canvas were built to verify the exact same 4-node network benchmark (CNN, Yahoo, TechCrunch, Amazon).
Open in any browser to create pages, link them together, and see the matrices update live:
Computes the analytical eigenvector and confirms it against 32 steps of Power Iteration:
Here is how the algorithm transforms a raw web of links into an exact ranking vector:
[ Web of Hyperlinks ]
│
▼
[ Step 1: Adjacency Matrix (A) ] ── Raw 1s and 0s (who links to whom)
│
▼
[ Step 2: Stochastic Matrix (S) ] ── Divide columns by outgoing links (probabilities sum to 1)
│
▼
[ Step 3: Google Matrix (M) ] ── Add 85% damping factor to fix dead-ends & loops
│
▼
[ Step 4: Eigenvector Solution ] ── Solve M·v = 1·v for the stationary distribution
│
▼
[ Step 5: Power Iteration Verification ] ── Multiply repeatedly until v converges (32 iterations)
We represent who links to whom as an
- Columns = Source page (From)
- Rows = Destination page (To)
- A value of
1means a link exists;0means no link.
An adjacency matrix only records connectivity. To turn it into probabilities, we normalize each column by the total number of outgoing links.
If a page has 2 outbound links, a visitor has a 50% chance of clicking either one. Every column now adds up to exactly
In the real world, two problems break raw Markov matrices:
- Dead ends (Rank Sinks): Pages with no outlinks absorb all the probability mass and cause math to crash.
- Spider traps: Loops of pages linking only to each other trap visitors in an infinite cycle.
To fix this, Google introduced the Random Surfer Model with a damping factor
- 85% of the time, the user clicks a real link on the page.
- 15% of the time, the user gets bored and jumps to a completely random URL across the web.
(where $N$ is total pages and $E$ is an $N \times N$ matrix of all 1s)
Because every entry in
We find the stationary probability vector
This vector
In real life, Google cannot invert a matrix with billions of rows. Instead, they use Power Iteration: start with an equal guess for all pages (
Because the non-dominant eigenvalues are small (
🔍 Click to expand: Full Matrix Math for the 4-Node Benchmark
Our 4-node network:
- CNN links to Yahoo and TechCrunch
- Yahoo links to CNN
- TechCrunch links to CNN and Amazon
- Amazon links to CNN
Adjacency Matrix (A): Stochastic Matrix (S):
CNN Yahoo TC Amz CNN Yahoo TC Amz
CNN 0 1 1 1 CNN 0.00 1.00 0.50 1.00
Yahoo 1 0 0 0 Yahoo 0.50 0.00 0.00 0.00
TechCrunch 1 0 0 0 TechCrunch0.50 0.00 0.00 0.00
Amazon 0 0 1 0 Amazon 0.00 0.00 0.50 0.00
Google Matrix (M) with d = 0.85:
CNN Yahoo TechCrunch Amazon
CNN 0.0375 0.8875 0.4625 0.8875
Yahoo 0.4625 0.0375 0.0375 0.0375
TechCrunch0.4625 0.0375 0.0375 0.0375
Amazon 0.0375 0.0375 0.4625 0.0375
Eigenvalues of M:
-
$\lambda_1 = 1.0000$ (The steady state PageRank) -
$\lambda_2 = -0.4250$ (Decays as$(-0.425)^{32} \approx 8 \times 10^{-13}$ ) $\lambda_3 = -0.4250$ $\lambda_4 = 0.0000$
Here are the final calculated ranks for our 4-node test network:
| Rank | Website | PageRank Score | Why it got this rank |
|---|---|---|---|
| #1 | CNN | 42.92% | Gets inbound links from Yahoo, TechCrunch, and Amazon |
| #2 | Yahoo | 21.99% | Gets half of CNN's outgoing vote |
| #3 | TechCrunch | 21.99% | Identical symmetric position to Yahoo |
| #4 | Amazon | 13.10% | Only receives a single link from TechCrunch |
Verification: The analytical result from
np.linalg.eigand the numerical result from 32-step Power Iteration match with a difference of only$0.000000000006$ ($6.36 \times 10^{-12}$ ).
- Double-click
index.htmlto open it in Chrome, Edge, Safari, or Firefox. - Click anywhere on the canvas to add pages.
- Drag from one page to another to create links.
- Watch the PageRank bars and matrices update in real time.
(Optional) You can also run it via a simple Python server:
python -m http.server 8080Then visit http://localhost:8080 in your browser.
- Make sure you have Python 3 and NumPy installed:
pip install numpy
- Run the script:
python pagerank_demo.py
- Choose an option:
- Press 1 (or hit Enter): Runs the default 4-node test network and prints all 5 math stages.
- Press 2: Lets you enter your own custom
$N \times N$ link matrix to calculate PageRank for any custom graph.
📥 Want to download the full project as a single ZIP?
You can download everything in one package:
- Click the green Code button at the top of this GitHub page.
- Select Download ZIP.
- Extract the folder and you have the complete presentation deck (
PageRank_Pro_Presentation.pptx), the Python scripts, the notes, and the interactive simulator ready to go!
| File | What it does |
|---|---|
index.html |
Interactive visual simulator (HTML5 Canvas + Vanilla JS). Runs anywhere. |
pagerank_demo.py |
Terminal Python script using NumPy to compute matrices and eigenvectors. |
HOW_TO_RUN.txt |
Quick-start cheat sheet with terminal commands and options. |
PageRank_Pro_Presentation.pptx |
16:9 widescreen presentation slides for project demo. |
Explanation_and_Notes.md |
Detailed mathematical notes and derivations. |
STUDENT_PRESENTATION_CHEATSHEET.md |
Oral presentation guide and examiner viva questions. |
LICENSE |
MIT Open Source License. |

