No history yet

Basic Probability Concepts

The World of Possibilities

Probability begins with a simple question: what could happen? The set of all possible outcomes of an experiment is called the sample space. If you flip a coin, the sample space is {Heads, Tails}. If you roll a standard six-sided die, the sample space is {1, 2, 3, 4, 5, 6}.

In computer science, a sample space could be all possible outputs of a random number generator, or the set of all possible 8-bit strings. It’s our map of everything that could occur.

An event is a specific outcome or a set of outcomes we're interested in. It's a subset of the sample space. For our die roll, the event "rolling an even number" corresponds to the subset {2, 4, 6}. The event "rolling a number greater than 4" is the subset {5, 6}.

The Rules of the Game

To work with probability, we need a few ground rules. These are known as the axioms of probability, and they ensure our calculations make sense. For any event EE in a sample space SS:

0P(E)10 \le P(E) \le 1

This first axiom says that the probability of an event is a number between 0 and 1. A probability of 0 means the event is impossible, while a probability of 1 means it's certain. You can't have a 150% chance of rain.

P(S)=1P(S) = 1

The second axiom states that the probability of the entire sample space is 1. This is just a formal way of saying that one of the possible outcomes must occur. When you roll a die, you're guaranteed to get a number between 1 and 6.

P(E1E2)=P(E1)+P(E2)P(E_1 \cup E_2) = P(E_1) + P(E_2)

The third axiom applies to mutually exclusive events—events that can't happen at the same time. For example, you can't roll a 1 and a 3 on a single die roll. If two events E1E_1 and E2E_2 are mutually exclusive, the probability that either of them happens is the sum of their individual probabilities. The probability of rolling a 1 or a 3 is P(1)+P(3)=1/6+1/6=2/6P(1) + P(3) = 1/6 + 1/6 = 2/6.

Counting Without Counting

To find the probability of an event, we often need to count the number of favorable outcomes and divide by the total number of outcomes. But counting one by one is slow and prone to errors. This is where combinatorics, the art of clever counting, comes in handy.

The fundamental counting principle states that if you have mm ways to do one thing and nn ways to do another, then there are m×nm \times n ways of doing both.

Imagine creating a user ID that must consist of two letters followed by one digit. There are 26 choices for the first letter, 26 for the second, and 10 for the digit (0-9). The total number of possible user IDs is 26×26×10=676026 \times 26 \times 10 = 6760.

Permutation

noun

An arrangement of objects in a specific order.

Sometimes, order matters. A permutation is an arrangement where the sequence is important. Think of a password: "p@ss" is different from "s@sp". The number of ways to arrange kk items from a set of nn distinct items is given by the formula:

P(n,k)=n!(nk)!P(n, k) = \frac{n!}{(n-k)!}

Let's say you have 5 distinct tasks to assign to 3 different servers. The order matters, since giving Task A to Server 1 is different from giving it to Server 2. Here, n=5n=5 and k=3k=3. The number of permutations is: P(5,3)=5!(53)!=5!2!=1202=60P(5, 3) = \frac{5!}{(5-3)!} = \frac{5!}{2!} = \frac{120}{2} = 60. There are 60 different ways to assign the tasks.

Combination

noun

A selection of objects where order does not matter.

Other times, order doesn't matter. A combination is a selection where the sequence is irrelevant. If you're choosing 3 programmers for a team from a group of 10, picking Alice, Bob, and Carol is the same as picking Carol, Alice, and Bob. The number of ways to choose kk items from a set of nn items is:

(nk)=n!k!(nk)!\binom{n}{k} = \frac{n!}{k!(n-k)!}

Suppose a network packet can take one of 20 routes, and 4 of them are congested. What is the probability of randomly selecting 3 routes and all of them are clear?

First, we find the total number of ways to choose 3 routes from 20: (203)=20!3!17!=1140\binom{20}{3} = \frac{20!}{3!17!} = 1140. This is our sample space size.

Next, we find the number of ways to choose 3 routes from the 16 that are not congested: (163)=16!3!13!=560\binom{16}{3} = \frac{16!}{3!13!} = 560. This is our number of favorable outcomes.

The probability is the ratio: P(3 clear routes)=56011400.49P(\text{3 clear routes}) = \frac{560}{1140} \approx 0.49.

With these foundations, you can start modeling uncertainty in algorithms, analyzing network reliability, or understanding the performance of a randomized process. Let's check your understanding.

Quiz Questions 1/5

A program generates a random integer from 1 to 10, inclusive. Which of the following sets represents the event of "generating a prime number"?

Quiz Questions 2/5

A data scientist claims that the probability of a specific network packet being dropped is -0.1. This is a valid probability value.

These concepts—sample spaces, events, axioms, and counting techniques—are the building blocks for navigating the uncertainty inherent in computer science.