Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-167

Graph Motif 3-Node Census

Problem

Count the two induced 3-node motifs of an undirected graph: triangles and open wedges.

A triangle has three edges; an open wedge is a path of length two whose endpoints are not adjacent. Return [triangles, open_wedges]. edges is a list of [u, v] pairs.

Hint

Every triple either closes into a triangle or stays an open wedge.

Test cases

case 1
in: [3,[[0,1],[1,2],[2,0]]]
expected: [1,0]
case 2
in: [4,[[0,1],[0,2],[0,3]]]
expected: [0,3]
case 3
in: [4,[[0,1],[1,2],[2,0],[2,3]]]
expected: [1,2]
case 4
in: [5,[[0,1],[1,2],[2,0],[0,3],[3,4],[4,0]]]
expected: [2,4]
Starter codePython
def motif_3_census(n, edges):
    # Your code here
    pass

4 test cases · run your code against them in the editor