Skip to content
DeepForgeby svx
All problems
MediumGraph Algorithmsgraph-119

Degeneracy Ordering

Problem

Compute a degeneracy (smallest-last) ordering of an undirected graph.

Repeatedly remove the node with the smallest current degree, breaking ties by smallest index, and record the removal order. Return the full ordering of n nodes. edges is a list of [u, v] pairs.

Hint

The largest degree seen during peeling is the graph degeneracy.

Test cases

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

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