Learn practical skills, build real-world projects, and advance your career

Introduction to Counting, Permutations and Combinations

This tutorial is a part of the Zero to Data Analyst Bootcamp by Jovian

alt

Solving problems in statistics and probability often involves counting events satisfying a criteria without listing them out. In this tutorial, we'll learn some basic counting techniques that can be combined in interesting ways. This tutorial covers the following topics:

  • Multiplication principle
  • Factorial rule
  • Permutations rule
  • Combinations rule
  • Computing probability using counting rules

Multiplication Principle of Counting

QUESTION: Your neighborhood Mexican restaurant "Tacos El Vegano" offer a "build your own burrito" option and claims that you create over 250 unique varieties by making the following choices:

  1. Choice of tortilla: white flour or whole wheat flour
  2. Choice of filling: potatoes, jackfruit or mushroom
  3. Choice of beans: red beans, black beans, kidney beans or no beans
  4. Choice of salad: lettuce, rocket or no salad
  5. Choice of grilled vegetables: yes or no
  6. Choice of guacamole: yes or no
alt

All the choices are made independently i.e. the choice of beans has no bearing on whether or not you can add guacamole and vice versa. Can you verify or refute this claim?

One way to check the validity of the claim is to systematically list all possible varieties:

  1. White flour, Potatoes, Red beans, Lettuce, Vegetables, Gaucamole
  2. White flour, Potatoes, Red beans, Lettuce, Vegetables, No Gaucamole
  3. White flour, Potatoes, Red beans, Lettuce, No Vegetables, Gaucamole
  4. White flour, Potatoes, Red beans, Lettuce, No Vegetables, No Gaucamole
  5. White flour, Potatoes, Red beans, Rocket, Vegetables, Gaucamole
  6. ...

This is a long, tedious and error prone process. Fortunately, there's an easier way:

alt

  • There are 2 choices for the tortilla (white flour or whole wheat flour).
  • Once a choice of tortilla is made, then the filling can be chosen in 3 ways (potatoes, jack fruit or mushroom) for each of the two choices. So, if we just consider the first two choices, we can create 3 + 3 = 2 * 3 = 6 total varieties.
  • Next, for each of these 6 combinations, we have 4 choices of beans (red beans, black beans, kidney beans or no beans). Thus the total number of varieties considering the first three choices are is 4 + 4 + 4 + 4 + 4 + 4 = 6 * 4 = 24.
  • and so on...

If you keep going, you will realize that the total number of varieties is simply the product of the number of options for each choice. We can compute this using Python:

n_tortilla = 2
n_filling = 3
n_beans = 4
n_salad = 3
n_vegetables = 2
n_guacamole = 2
n_variations = n_tortilla * n_filling * n_beans * n_salad * n_vegetables * n_guacamole