Skip to content
Graph Intelligence Hub
Menu

Algorithm

PageRank

activeNeeds verification

Scores nodes by the stationary probability that a random surfer — following links, occasionally teleporting — is on them. Originally used to rank web pages.

Definition

Intuition

A page is important if important pages link to it; the damping factor d (often 0.85) models a surfer who sometimes jumps to a random page.

Pseudocode

PR[v] = 1/N for all v
repeat until converged:
  for v: new[v] = (1-d)/N + d * Σ_{u→v} PR[u] / outdeg(u)
  PR = new     # dangling nodes redistribute mass uniformly

Complexity

TimeO(k (V + E)) for k iterations
SpaceO(V)

Python

import networkx as nx
pr = nx.pagerank(G, alpha=0.85)

Cypher (Neo4j GDS)

CALL gds.pageRank.stream('myGraph', {dampingFactor: 0.85})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score ORDER BY score DESC

Procedure names and options vary between GDS versions; check the GDS docs for your version.

An interactive step-by-step visualizer for this algorithm is planned for phase 3.

Profile

Time complexityO(k (V + E)) for k iterations
Space complexityO(V)

Relationships

Belongs to
Prerequisite of
Prerequisites
Implemented by
Related