All problems
Betweenness Normalization
Problem
Normalize raw betweenness values of an undirected graph.
For undirected graphs the number of possible intermediate pairs is (n - 1) * (n - 2) / 2, so divide each value by that count. Return zeros when n is less than 3. values is the raw betweenness list.
Hint
Normalization turns raw path counts into the fraction of pairs passing through the node.
Test cases
case 1
in: [4,[0,2,2,0]]
expected: [0,0.6666666666666666,0.6666666666666666,0]
case 2
in: [3,[1,2,3]]
expected: [1,2,3]
case 3
in: [2,[5,5]]
expected: [0,0]
case 4
in: [5,[0,6,6,6,0]]
expected: [0,1,1,1,0]
Starter codePython
def normalize_betweenness(n, values):
# Your code here
pass4 test cases · run your code against them in the editor