Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-095

Personalized PageRank Normalize

Problem

Normalize a Personalized PageRank vector so its entries sum to 1.

Divide every entry by the total sum. If the sum is 0, return a list of zeros of the same length. ranks is the raw rank list.

Hint

Dividing by the sum makes the vector a probability distribution again.

Test cases

case 1
in: [[1,1,2]]
expected: [0.25,0.25,0.5]
case 2
in: [[0,0,0]]
expected: [0,0,0]
case 3
in: [[2.5,2.5]]
expected: [0.5,0.5]
case 4
in: [[3]]
expected: [1]
Starter codePython
def normalize_ppr(ranks):
    # Your code here
    pass

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