All problems
Tensor Product Edge Count
Problem
Compute the number of edges in the tensor (categorical) product G1 x G2 of two undirected graphs.
An edge exists in the product exactly when both coordinates change along an edge, so each pair of factor edges yields two directed edges, or 2 * m1 * m2 total undirected edges. Return the count.
Hint
Every pair of edges in the factors produces two product edges, one per orientation.
Test cases
case 1
in: [[[0,1]],[[0,1],[1,2]]]
expected: 4
case 2
in: [[[0,1],[1,2]],[[0,1]]]
expected: 4
case 3
in: [[],[[0,1]]]
expected: 0
case 4
in: [[[0,1],[1,2],[2,0]],[[0,1]]]
expected: 6
Starter codePython
def tensor_product_edges(edges1, edges2):
# Your code here
pass4 test cases · run your code against them in the editor