Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-086

PGF of Geometric

Problem

Probability generating function of the geometric distribution for the number of trials until the first success:

G(z) = p * z / (1 - (1 - p) * z).

Return 0.0 when the denominator is 0.

Hint

Sum p * ((1 - p) * z)^(k - 1) * z over k >= 1.

Test cases

case 1
in: [0.5,1]
expected: 1
case 2
in: [0.5,0]
expected: 0
case 3
in: [0.2,0.5]
expected: 0.16666666666666669
case 4
in: [0.5,2]
expected: 0
Starter codePython
def pgf_geometric(p, z):
    # Your code here
    pass

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