All problems
M/M/1 Occupancy Probability
Problem
Steady-state probability that an M/M/1 queue with arrival rate lam and service rate mu contains exactly n customers:
P(N = n) = (1 - rho) * rho^n with rho = lam / mu.
Return 0.0 when rho >= 1 (unstable queue) or for invalid inputs.
Hint
The geometric steady state exists only when the arrival rate is below the service rate.
Test cases
case 1
in: [1,2,0]
expected: 0.5
case 2
in: [1,2,1]
expected: 0.25
case 3
in: [2,3,0]
expected: 0.33333333333333337
case 4
in: [1,1,0]
expected: 0
case 5
in: [0,2,3]
expected: 0
Starter codePython
def mm1_occupancy_probability(lam, mu, n):
# Your code here
pass5 test cases · run your code against them in the editor