Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Who should this vertex connect to next?
Random walk with restart from the start vertex: scores every vertex by its closeness to it and suggests the best ones not yet linked
Select an algorithm and generate steps to begin visualization
Personalized PageRank scores every vertex by how close it is to one chosen vertex, the seed, through many short paths. It is PageRank with a different jump: the random surfer follows a random link with probability d = 0.85, and otherwise returns to the seed instead of to a random page. Glen Jeh and Jennifer Widom described it in 2003, and the same idea is known as random walk with restart. The scores answer personal questions: which pages, products or people matter most from this vertex's point of view.
All of the score starts on the seed. In every iteration each vertex passes 85% of its score evenly along its links, and the remaining 15% of the total returns to the seed, together with the score of vertices that have no links. The walk first reaches the seed's neighbours, then their neighbours, and the scores settle after a few dozen iterations, as each change is about 0.85 times the one before. A vertex scores high when many short paths lead to it from the seed, so a friend of three friends beats a friend of one. The best vertices that are not yet linked to the seed are its recommendations.
Social networks use it for "people you may know" suggestions, Twitter's Who To Follow service was built on it, and online shops and streaming services rank products and films by how close they are to what a user already likes. It also finds local communities around a vertex, ranks related pages in search, spreads suspicion from known fraudulent accounts to their close contacts, and in biology finds the proteins most related to a known disease gene.
Personalized PageRank is PageRank with a home. The random walker follows a random edge with probability d, and otherwise jumps back to one seed vertex instead of to a random page, so the scores measure closeness to the seed.
PersonalizedPageRank(graph, seed, d = 0.85, tol = 0.0001):
PPR[v] = 0 for every v, PPR[seed] = 1
repeat:
new[v] = 0 for every v
new[seed] = 1 - d
for each vertex u, for each neighbor v of u:
new[v] = new[v] + d * PPR[u] / deg(u)
(a vertex with no edges returns its share to seed)
change = max over v of |new[v] - PPR[v]|
PPR = new
until change < tol
return PPRPPR[v] is the long-run fraction of time a walker restarting at the seed spends at v. Equivalently, it is a weighted sum over all walks from the seed to v, where a walk of length k is weighted by (1 - d) d^k times its probability. Short walks dominate, so vertices reachable from the seed by many short routes score highest, which is exactly what friend recommendation needs.
Recommend new friends for A on the example this page loads, a small friendship network in which one person, H, is far more connected than anyone else.
Example graph: Undirected friendships A-B, A-C, A-D, B-C, B-E, C-E, D-E, D-F, B-G, E-G, F-H, G-H, H-I, H-J and H-K. A already knows B, C and D. H has five friends, the most in the network.
The final scores are A 25.3 percent, B 15.5, C 13.1, E 12.3, D 11.7, G 7.1, H 6.9, F 4.5, and 1.2 each for I, J and K. Leaving out A and the people A already knows, the recommendations are E (12.3), G (7.1) and H (6.9). E shares three friends with A and comes first. Plain PageRank on the same graph puts H on top with 18.7 percent, because it only sees that H is the best connected person, not that H is far from A.
Time: O(k (V + E)) per seed · Space: O(V)
Each iteration of power iteration passes over every edge once, O(V + E), and the error shrinks by a factor of about d per iteration, so k is a few dozen for typical tolerances, 29 here. Computing it for one seed therefore costs about as much as plain PageRank. For large graphs, local push methods such as that of Andersen, Chung and Lang approximate the vector in time that depends on the tolerance and the restart probability but not on the size of the graph, because they only touch vertices near the seed. Monte Carlo estimation with a few thousand short random walks is another common approach in production recommenders.
Several measures rank vertices by their relation to one seed. They differ in how far they look and how they treat hubs.
| Alternative | Prefer it when | Cost |
|---|---|---|
| PageRank | You want global importance, the same ranking for every user, rather than relevance to one seed. | O(k (V + E)) |
| Common neighbours or Adamic-Adar | Only friends of friends matter. Counting shared neighbours, weighted down for popular ones, is cheaper and often as good. | O(sum of degrees squared) |
| Katz index | You want all paths between two vertices counted, with geometric decay by length, without the random walk normalisation. | matrix inversion |
| Node embeddings | Large graphs where similarity should also capture structural roles. Methods like node2vec train on random walks. | training cost |
Read the full article: Graph Centrality Measures and PageRank
Read the full article: Applications of Graph Theory in the Real World
Related algorithms: PageRank, Betweenness Centrality, Label Propagation, Breadth-First Search