Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-117

Rich-Club Coefficient Lite

Problem

Compute the rich-club coefficient at degree threshold k for an undirected graph.

Consider the nodes with degree strictly greater than k; if there are fewer than two, return 0.0. Otherwise return 2 * E / (m * (m - 1)), where E is the number of edges among those nodes and m their count. edges is a list of [u, v] pairs.

Hint

A coefficient above the random baseline suggests the rich nodes form a club.

Test cases

case 1
in: [4,[[0,1],[0,2],[0,3]],0]
expected: 0.5
case 2
in: [4,[[0,1],[0,2],[0,3]],1]
expected: 0
case 3
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]],1]
expected: 1
case 4
in: [4,[[0,1],[1,2],[2,3]],1]
expected: 1
Starter codePython
def rich_club_coefficient(n, edges, k):
    # Your code here
    pass

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