Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-155

Expected Degree in G(n,p)

Problem

Expected degree of a fixed vertex in the Erdos-Renyi random graph G(n, p):

E[degree] = (n - 1) * p.

Each of the n - 1 possible edges appears independently. Return 0.0 for n <= 0.

Hint

Sum the edge-indicator expectations for one vertex.

Test cases

case 1
in: [10,0.5]
expected: 4.5
case 2
in: [5,0.2]
expected: 0.8
case 3
in: [1,0.9]
expected: 0
Starter codePython
def expected_degree(n, p):
    # Your code here
    pass

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