Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-107

G(n,p) Expected Edges

Problem

The Erdos-Renyi random graph G(n, p) has each of the C(n, 2) possible edges present independently with probability p. Return the expected number of edges:

E[edges] = C(n, 2) * p.

Return 0.0 for negative n.

Hint

Sum the edge-indicator expectations.

Test cases

case 1
in: [10,0.5]
expected: 22.5
case 2
in: [5,0.1]
expected: 1
case 3
in: [1,0.9]
expected: 0
case 4
in: [0,0.5]
expected: 0
Starter codePython
def gn_p_expected_edges(n, p):
    # Your code here
    pass

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