All problems
Graph Partition Balance
Problem
Measure the balance of a graph partition given as a community assignment list.
Return [largest_community_size, smallest_community_size] over all distinct community labels. community is a list mapping each node to a label.
Hint
Balanced partitions have a ratio near 1 between largest and smallest blocks.
Test cases
case 1
in: [[0,0,1,1,2]]
expected: [2,1]
case 2
in: [[0,1,2,3]]
expected: [1,1]
case 3
in: [[1,1,1]]
expected: [3,3]
case 4
in: [[0,0,1]]
expected: [2,1]
Starter codePython
def partition_balance(community):
# Your code here
pass4 test cases · run your code against them in the editor