All problems
Hypergraph Node Degree
Problem
Compute the degree of every node of a hypergraph: the number of hyperedges that contain it.
A node counts each containing hyperedge at most once, even if listed several times. Return the degree list in node order. n is the number of nodes and hyperedges is a list of vertex lists.
Hint
Hypergraph degree counts incident hyperedges, not edge-endpoint incidences.
Test cases
case 1
in: [3,[[0,1],[1,2]]]
expected: [1,2,1]
case 2
in: [2,[]]
expected: [0,0]
case 3
in: [2,[[0,0,1]]]
expected: [1,1]
case 4
in: [3,[[0,1,2],[0,1]]]
expected: [2,2,1]
Starter codePython
def hypergraph_degrees(n, hyperedges):
# Your code here
pass4 test cases · run your code against them in the editor