Course contentsShow
← Computer Science
Lesson 126 of 2,8723. Probability for Computer ScienceFree lesson

Geometric Distribution

Model number of trials until first success; compute probabilities using geometric formula.

Geometric Distribution

You'll learn: How to model the number of attempts needed to achieve your first success in repeated, independent trials.


What Is the Geometric Distribution?

Imagine you're flipping a coin, trying to get heads. You might get it on your first try, or you might need 2, 3, or even 10 flips. The geometric distribution models exactly this scenario: how many trials do you need until you get your first success?

Unlike the binomial distribution (which counts total successes in a fixed number of trials), the geometric distribution focuses on when that first success happens.

The Setup

You need:

  • Independent trials (each attempt doesn't affect others)
  • Each trial has the same probability of success, p
  • You stop as soon as you get your first success

The Formula

The probability that your first success occurs on trial k is:

P(X = k) = (1 - p)^(k-1) · p

Breaking this down:

  • (1 - p)^(k-1) means you failed k-1 times in a row
  • p means you succeeded on the k-th trial

Example: You're testing a program that crashes randomly with probability 0.2. What's the probability it first crashes on the 3rd run?

P(X = 3) = (1 - 0.2)^(3-1) · 0.2 = (0.8)² · 0.2 = 0.64 · 0.2 = 0.128

You had two successful runs, then crashed on the third.


Key Takeaway: The geometric distribution models "trials until first success" using P(X = k) = (1 - p)^(k-1) · p, where p is the success probability and k is the trial number of the first success.