All problems
Heterogeneous Graph Degree
Problem
Compute the total degree of each node type in a heterogeneous graph.
nodes_types[i] is the type string of node i and typed_edges is a list of [u, v, type] triples. Each edge contributes one incidence to each endpoint's degree. Return a dictionary mapping each node type to the sum of degrees of its nodes.
Hint
Type-level degree sums aggregate the activity of each node class.
Test cases
case 1
in: [["user","user","item","item"],[[0,2,"buy"],[1,2,"buy"],[0,3,"view"]]]
expected: {"user":3,"item":3}
case 2
in: [["a","b","a"],[[0,1,"x"],[1,2,"y"]]]
expected: {"a":2,"b":2}
case 3
in: [["x"],[]]
expected: {"x":0}
Starter codePython
def heterogeneous_degree(node_types, typed_edges):
# Your code here
pass3 test cases · run your code against them in the editor