Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-136

Degree Buckets Summary

Problem

Summarize the degree distribution of an undirected graph with n nodes.

Count how many nodes have each degree, including degree 0, and return a list of [degree, count] pairs sorted by degree. edges is a list of [u, v] pairs.

Hint

The degree distribution is one of the simplest graph fingerprints.

Test cases

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

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