Cars on the Road

if the probability of observing a car in 20 minutes on a highway is 609/625, what is the probability of observing a car in 5 minutes (assuming constant default probability)?

Solution

I haven’t written up a solution for this yet, but smarter people than I have described some on the discussion forum.

You can read their thoughts here.

2026 Update: Traffic Flow — Modeling with Queuing Theory

Car arrival and flow problems map directly to queuing theory — one of the most practically useful areas of probability in computer science (load balancers, request queues, thread pools).

import math
import random

# Problem setup: cars arrive at 10/minute, pass an observation point
# What's the probability of seeing 0, 1, 2, ... cars in a 30-second window?

def poisson_pmf(lam: float, k: int) -> float:
    return math.exp(-lam) * (lam ** k) / math.factorial(k)

rate = 10  # cars per minute
window = 0.5  # 30 seconds = 0.5 minutes
lam = rate * window  # Expected arrivals = 5

print(f"Expected cars in 30 sec: {lam}")
print("Probability distribution:")
for k in range(12):
    p = poisson_pmf(lam, k)
    print(f"  P(X={k:2d}) = {p:.4f} {'|' * int(p * 40)}")

# Traffic flow model: M/M/1 queue
# Arrival rate: lambda, Service rate: mu (e.g., intersection processing)
def mm1_queue(arrival_rate: float, service_rate: float) -> dict:
    """M/M/1 queue metrics (Poisson arrivals, exponential service times)."""
    if arrival_rate >= service_rate:
        return {"error": "System unstable: arrival rate >= service rate"}

    rho = arrival_rate / service_rate  # Utilization = traffic intensity

    L = rho / (1 - rho)       # Average queue length (incl. being served)
    Lq = rho**2 / (1 - rho)  # Average waiting in queue
    W = L / arrival_rate      # Average time in system (Little's Law)
    Wq = Lq / arrival_rate    # Average waiting time

    return {
        "utilization": rho,
        "avg_in_system": L,
        "avg_in_queue": Lq,
        "avg_time_in_system_min": W,
        "avg_wait_in_queue_min": Wq,
    }

# Example: traffic intersection
# 8 cars/min arrive, intersection processes 10 cars/min
metrics = mm1_queue(8, 10)
for k, v in metrics.items():
    print(f"  {k}: {v:.4f}" if isinstance(v, float) else f"  {k}: {v}")

# Little's Law: L = lambda * W
# (Number in system = arrival rate * time in system)
# This applies to ANY stable queuing system, not just M/M/1!
print(f"nLittle's Law check: L = lambda * W = {8 * metrics['avg_time_in_system_min']:.4f}")
print(f"                   L = {metrics['avg_in_system']:.4f}")

System design connection: M/M/1 queue is the model for a single-threaded server. For k parallel threads: M/M/k queue. The key insight: when utilization ρ → 1, latency → ∞. This is why you never run servers at 100% — at 90% utilization, average queue length is 9×; at 99%, it’s 99×. System design rule: target 50-70% peak utilization to keep latency manageable.

Scroll to Top