Hello! Welcome to the first lesson in our new module, Probability and Statistics with Python.
In the previous modules, we built a strong foundation in Python, Linear Algebra, and Calculus. These are essential tools for data science. Now, we dive into the core concepts that allow us to reason about uncertainty and make sense of data.
Probability is often defined as the ratio of favorable outcomes to the total number of possible outcomes. But before we can calculate that ratio, we first need to be able to count the outcomes. This is where combinatorics—the mathematics of counting—comes in. Today, our goal is to apply fundamental counting principles, including permutations and combinations. Mastering these skills is the first and most crucial step on our journey through probability.
1. The Fundamental Counting Principles
At the heart of all counting problems are two simple but powerful ideas: the Product Rule and the Sum Rule.
The Product Rule (Multiplication Principle)
Imagine you are building a computer. You have 3 CPU choices, 4 RAM choices, and 2 hard drive choices. How many different computer configurations can you build? Since you must choose one of each, you multiply the options: possible configurations.
This is the Product Rule: If a procedure can be broken down into a sequence of independent tasks, the total number of ways to perform the procedure is the product of the number of ways to do each task.

The Sum Rule (Addition Principle)
Now, imagine you want to travel from City A to City B. You can take one of 3 different bus routes or one of 2 different train routes. Since you can only take a bus or a train (not both at the same time), your total number of travel options is the sum: options.
This is the Sum Rule: If you have to choose between one of ways to do a task or one of ways to do another, and the tasks are mutually exclusive (you can't do both), the total number of ways is the sum .
To see these principles in action with more examples relevant to your GATE preparation, please watch the following video segment.
Introduction to Probability & Statistics | GATE Data Science and Artificial Intelligence
This video from GeeksforGeeks GATE explains the Sum and Product rules with clear examples, including one about forming license plates which is a classic problem type.
Watch from 00:12:44 to 00:21:35. Pay attention to how the narrator decides whether to add or multiply the options based on the problem's wording (e.g., choosing 'from' a list vs. performing a 'sequence of' tasks).
2. Permutations: When Order Matters
Now let's get more specific. A permutation is an arrangement of objects in a specific order. Think about the top three finishers in a race. Gold, Silver, Bronze is a different outcome from Bronze, Silver, Gold, even if it's the same three people. The order matters.
Factorials
To count arrangements, we use the factorial function, denoted by an exclamation mark !. For a positive integer , (read as "n factorial") is the product of all positive integers up to .
For example, . By definition, .
The number of ways to arrange distinct items is simply .
The Permutation Formula
What if we don't want to arrange all the items? What if we want to select and arrange only items from a total of items? This is denoted as or .
The formula for permutations is:
Example: In a club of 10 members, how many ways can we select a President, Vice-President, and Treasurer?
Here, we are selecting 3 people out of 10, and the order matters (President VP).
- (total members)
- (positions to fill)
There are 720 ways to choose the officers.
For a clear explanation and the formula, please consult this resource.
This article from AlmaBetter provides a concise definition of permutations, the formula, and a simple example.
Read the section titled 'Permutations' to solidify your understanding of the definition and formula.
3. Combinations: When Order Doesn't Matter
A combination is a selection of items where the order does not matter. Think about forming a study group. A group with students A, B, and C is the exact same group as C, B, and A.
The formula for combinations, denoted or , is:
Notice this is just the permutation formula divided by . We divide by to eliminate the different arrangements of the chosen items, since we don't care about their order.
Example: From the same club of 10 members, how many ways can we form a committee of 3 people?
Here, we are selecting 3 people out of 10, but the order doesn't matter.
There are 120 ways to form the committee. As expected, this is fewer than the 720 permutations.

To deepen your understanding, let's turn back to the GeeksforGeeks video, which explains the distinction with a GATE-oriented perspective.
Introduction to Probability & Statistics | GATE Data Science and Artificial Intelligence
This segment of the video differentiates between permutations and combinations and provides examples for each.
Watch from 00:06:14 to 00:12:44. Focus on the keywords that signal whether a problem requires a permutation ('arrange', 'order', 'signal') versus a combination ('select', 'choose', 'poker hand').
Test your understanding!
You have a bookshelf with 8 different books.
- How many different ways can you arrange all 8 books on the shelf?
- How many ways can you pick 3 books to lend to a friend?
Is problem 1 a permutation or combination? What about problem 2?
Show answer
-
Arranging all 8 books: This is a permutation because the order of books on the shelf matters. We are arranging all 8 items, so it's .
ways. -
Picking 3 books to lend: This is a combination because it doesn't matter in what order you pick the three books; the friend receives the same set of books.
ways.
4. The Pigeonhole Principle
Another fundamental counting idea is the Pigeonhole Principle. It states that if you have more "pigeons" than "pigeonholes," at least one pigeonhole must contain more than one pigeon.
While it sounds obvious, it's a powerful tool for proving existence.
- Example: In a class of 30 students, can you guarantee at least two students share a birthday month?
- Pigeons = 30 students
- Pigeonholes = 12 months
- Since , yes, at least one month must have more than one student's birthday.
The GFG video provides some excellent examples that are common in competitive exams like GATE.
Introduction to Probability & Statistics | GATE Data Science and Artificial Intelligence
Let's watch the final segment of the video to understand the Pigeonhole Principle and how to apply it to solve problems.
Watch from 00:21:35 to 00:33:04. Focus on the 'worst-case scenario' logic used to solve these problems, like with the marbles and cards examples.
5. Counting in Python with itertools
As you know, we always want to bridge theory with practice. Python's standard library has a fantastic module called itertools that handles permutations and combinations for us. This is great for quickly generating all possibilities to check your reasoning or solve a coding problem.
Permutations and Combinations in Python
This tutorial from DigitalOcean shows how to use the itertools module to generate permutations and combinations. We'll focus on the key functions.
Read the sections 'Permutations of fixed length' and 'Combinations of Numeric data'. See how the itertools.permutations() and itertools.combinations() functions work. Notice that combinations requires a length argument, while permutations can take an optional one.
Here is a quick example demonstrating the difference:
import itertools
my_list = ['A', 'B', 'C']
# Permutations of length 2: Order matters ('A', 'B') is different from ('B', 'A')
perms = itertools.permutations(my_list, 2)
print("Permutations of length 2:")
for p in perms:
print(p)
# Output includes ('A', 'B'), ('B', 'A'), ('A', 'C'), ('C', 'A'), etc.
print("-" * 20)
# Combinations of length 2: Order does not matter ('A', 'B') is the same as ('B', 'A')
combs = itertools.combinations(my_list, 2)
print("Combinations of length 2:")
for c in combs:
print(c)
# Output includes ('A', 'B'), ('A', 'C'), ('B', 'C') but NOT the reverse pairs.
Conclusion
In this lesson, we laid the groundwork for our study of probability by learning how to count. You now have the essential tools to determine the number of possible outcomes in various scenarios.
Key Takeaways:
- Product Rule: Use when tasks are sequential (AND). Total ways = product of ways for each task.
- Sum Rule: Use when tasks are mutually exclusive choices (OR). Total ways = sum of ways for each task.
- Permutations: Arrangements where order matters. Use .
- Combinations: Selections where order does not matter. Use .
- Pigeonhole Principle: A simple but powerful rule for proving that at least one category must contain multiple items.
Preview of the Next Lesson:
Now that we can count the number of outcomes, we are ready to start assigning probabilities to them. In the next lesson, we will move from "how many?" to "how likely?". We will learn how to calculate probabilities using axioms, conditional probability, and the famous Bayes' theorem.