PageRank Algorithm
PageRank scores nodes (web pages) based on link structure using a random-surfer Markov model with damping factor. Authority flows through links; pages linked by important pages receive higher rank. Iterative power method converges to stationary distribution.
Visualization
Interactive visualization for PageRank Algorithm
Interactive visualization with step-by-step execution
Implementation
1function pageRank(graph: Map<number, number[]>, d = 0.85, iterations = 100): Map<number, number> {
2 const nodes = Array.from(graph.keys());
3 const n = nodes.length;
4 const ranks = new Map(nodes.map(v => [v, 1 / n]));
5 const outlinks = new Map(nodes.map(v => [v, (graph.get(v) ?? []).length || 1]));
6
7 for (let iter = 0; iter < iterations; iter++) {
8 const newRanks = new Map<number, number>();
9 for (const v of nodes) {
10 let sum = 0;
11 for (const [u, neighbors] of graph) {
12 if (neighbors.includes(v)) {
13 sum += ranks.get(u)! / outlinks.get(u)!;
14 }
15 }
16 newRanks.set(v, (1 - d) / n + d * sum);
17 }
18 Object.assign(ranks, newRanks);
19 }
20 return ranks;
21}Deep Dive
Theoretical Foundation
Let d be damping (typically 0.85), N the number of nodes, and L(u) the out-degree. PageRank satisfies PR(v) = (1-d)/N + d × Σ_{u→v} PR(u)/L(u). In matrix form, PR is the stationary distribution of a stochastic matrix with teleportation; compute via power iteration with dangling-node correction (distribute rank of zero-outdegree nodes uniformly).
Complexity
Time
O(k×(V+E))
O(k×(V+E))
O(k×(V+E))
Space
O(V)
Applications
Industry Use
Web search result ranking
Citation network analysis (paper influence)
Social influence and recommendation systems
Fraud/spam detection via link anomalies
Protein interaction networks
Knowledge graph entity ranking
Use Cases
Related Algorithms
Depth-First Search (DFS)
Graph traversal exploring as deep as possible before backtracking. DFS is a fundamental algorithm that uses a stack (either implicitly through recursion or explicitly) to explore graph vertices. It's essential for cycle detection, topological sorting, and pathfinding problems.
Breadth-First Search (BFS)
Level-by-level graph traversal guaranteeing shortest paths in unweighted graphs. BFS uses a queue to explore vertices level by level, making it optimal for finding shortest paths and solving problems that require exploring nearest neighbors first.
Dijkstra's Algorithm
Finds shortest path from source to all vertices in weighted graph with non-negative edges. Uses greedy approach with priority queue.
Floyd-Warshall Algorithm
Floyd-Warshall is an all-pairs shortest path algorithm that finds shortest distances between every pair of vertices in a weighted graph. Unlike Dijkstra (single-source), it computes shortest paths from all vertices to all other vertices simultaneously. The algorithm can handle negative edge weights but not negative cycles. Developed independently by Robert Floyd, Bernard Roy, and Stephen Warshall in the early 1960s.