Skip to content
DeepForgeby svx
All problems
HardGraph Algorithmsgraph-349

PageRank Teleport Step

Problem

Perform one PageRank iteration with a custom teleport distribution.

Start from the uniform vector 1/n, let p be weights normalized to sum to 1, and use new[j] = (1 - d) * p[j] + d * p[j] * dangling + d * sum of rank[u] / outdeg(u) over edges u -> j. Rank carried by dangling nodes is redistributed by p, not uniformly. weights must contain at least one positive entry.

Hint

Dangling mass joins the teleport term, and every rank vector entry must still sum to 1.

Test cases

case 1
in: [2,[[0,1],[1,1]],0.85,[1,1]]
expected: [0.075,0.925]
case 2
in: [2,[],0.85,[1,3]]
expected: [0.25,0.75]
case 3
in: [3,[[0,1],[1,2]],0.5,[1,1,1]]
expected: [0.2222222222222222,0.3888888888888889,0.3888888888888889]
case 4
in: [1,[],0.85,[5]]
expected: [1]
case 5
in: [2,[[0,1]],0.5,[1,0]]
expected: [0.75,0.25]
Starter codePython
def pagerank_teleport_step(n, edges, damping, weights):
    # Your code here
    pass

5 test cases · run your code against them in the editor