All problems
Degree Distribution Fit Slope
Problem
Fit the slope of the degree distribution on a log-log plot.
Count how many nodes have each positive degree, take logs of degree and count, and compute the least-squares slope of count versus degree. Return 0.0 when fewer than two distinct degrees exist or the fit is degenerate. edges is a list of [u, v] pairs.
Hint
Scale-free networks show an approximately straight line with negative slope on log-log axes.
Test cases
case 1
in: [5,[[0,1],[1,2],[2,3],[3,4]]]
expected: 0.5849625007211563
case 2
in: [4,[[0,1],[1,2],[2,3]]]
expected: 0
case 3
in: [4,[[0,1],[0,2],[0,3]]]
expected: -1
case 4
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]]
expected: 0
Starter codePython
import math
def degree_slope(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor