All problems
Triangle Transitivity
Problem
Compute the transitivity of an undirected graph: 3 * triangles / triples, where a triple is a path of length two centered at some node.
The triple count is the sum of degree choose 2 over all nodes. Return 0.0 when there are no triples. edges is a list of [u, v] pairs.
Hint
Each triangle closes exactly three open triples.
Test cases
case 1
in: [3,[[0,1],[1,2],[2,0]]]
expected: 1
case 2
in: [4,[[0,1],[0,2],[0,3]]]
expected: 0
case 3
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]]
expected: 1
case 4
in: [4,[[0,1],[1,2],[2,0],[2,3]]]
expected: 0.6
Starter codePython
def transitivity(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor