Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-248

K-Truss Decomposition Step

Problem

Compute the k-truss of an undirected graph: the largest edge set where every edge lies in at least k - 2 triangles within the set.

Repeatedly delete edges with too few triangle supports until stable, then return the remaining edges sorted as [u, v] pairs. n is the number of nodes and edges is a list of [u, v] pairs.

Hint

Triangle counts drop as edges are removed, so k-truss peeling iterates to a fixed point.

Test cases

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

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