All problems
Global Clustering Coefficient
Problem
Compute the global clustering coefficient: the average of the local clustering coefficients of all n nodes.
A node with degree less than 2 contributes 0.0. edges is a list of [u, v] pairs. Return the mean value.
Hint
This average differs from transitivity, which weights nodes by their triple count.
Test cases
case 1
in: [4,[[0,1],[1,2],[2,0],[2,3]]]
expected: 0.5833333333333334
case 2
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]]
expected: 1
case 3
in: [4,[[0,1],[0,2],[0,3]]]
expected: 0
case 4
in: [4,[[0,1],[1,2],[2,3]]]
expected: 0
Starter codePython
def global_clustering(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor