🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Counting Principles — Permutations and Combinations

Foundations of StatisticsProbability Theory🟢 Free Lesson

Advertisement

Counting Principles

Probability Theory

Count Without Listing Every Outcome

Counting principles give you formulas for the number of ways events can occur — without actually listing them all. They are the foundation of probability calculations.

  • Multiplication principle — Multiply choices across independent stages
  • Permutations — Order matters; arrange r items from n distinct items
  • Combinations — Order does not matter; choose r items from n
  • Binomial coefficient — The number of ways to choose r successes from n trials

Counting is the bridge between "how many ways" and "what is the probability."


What is the Fundamental Counting Principle?

Definition

If there are n1n_1 ways to do task 1, n2n_2 ways to do task 2, and so on, the total number of ways to do all tasks is their product.

Multiplication Principle

Total ways=n1×n2××nk\text{Total ways} = n_1 \times n_2 \times \cdots \times n_k

Here,

  • n1,n2,,nkn_1, n_2, \ldots, n_k=Number of choices for each task
# Example: 3 shirts, 4 pants, 2 shoes
shirts = 3
pants = 4
shoes = 2
total_outfits = shirts * pants * shoes
print(f"Total outfits = {shirts} × {pants} × {shoes} = {total_outfits}")

Factorials

Factorial

n!=n×(n1)×(n2)××2×1n! = n \times (n-1) \times (n-2) \times \cdots \times 2 \times 1

Here,

  • n!n!=n factorial — product of all positive integers up to n
  • 0!=10! = 1=By definition
import math
from itertools import permutations, combinations

# Factorials
for n in range(1, 8):
    print(f"{n}! = {math.factorial(n)}")

Permutations (Order Matters)

DfPermutation

A permutation is an arrangement of objects in a specific order. The number of permutations of n objects taken r at a time is n!/(n-r)!.

Permutations

P(n,r)=n!(nr)!P(n, r) = \frac{n!}{(n - r)!}

Here,

  • nn=Total number of objects
  • rr=Number of objects to arrange
  • P(n,r)P(n, r)=Number of ordered arrangements
# Permutations: arranging 3 books from 5
n, r = 5, 3
perm = math.perm(n, r)
print(f"P({n}, {r}) = {n}!/{n-r}! = {perm}")

# List all permutations
books = ['A', 'B', 'C', 'D', 'E']
for p in permutations(books, 3):
    print(f"  {p}")

Combinations (Order Doesn't Matter)

DfCombination

A combination is a selection of objects where order does not matter. The number of combinations of n objects taken r at a time is n!/(r!(n-r)!).

Combinations (Binomial Coefficient)

(nr)=n!r!(nr)!\binom{n}{r} = \frac{n!}{r!(n - r)!}

Here,

  • (nr)\binom{n}{r}=Read as 'n choose r'
  • nn=Total number of objects
  • rr=Number of objects to select
# Combinations: choosing 3 books from 5
n, r = 5, 3
comb = math.comb(n, r)
print(f"C({n}, {r}) = {n}!/({r}!×{n-r}!) = {comb}")

# List all combinations
for c in combinations(books, 3):
    print(f"  {c}")

Permutations with Repeated Elements

Permutations with Repetition

n!n1!×n2!××nk!\frac{n!}{n_1! \times n_2! \times \cdots \times n_k!}

Here,

  • n1,n2,,nkn_1, n_2, \ldots, n_k=Counts of each repeated element
# Arranging letters in "MISSISSIPPI"
from collections import Counter

word = 'MISSISSIPPI'
counts = Counter(word)
denominator = math.prod(math.factorial(v) for v in counts.values())
result = math.factorial(len(word)) // denominator

print(f"'{word}' has {len(word)} letters")
print(f"Letter counts: {dict(counts)}")
print(f"Distinct arrangements = {len(word)}!/({' × '.join(str(v) for v in counts.values())}) = {result}")

Counting Principles in Machine Learning

ML ApplicationCounting UsageWhy
Combinatorial optimizationHyperparameter search spaceGrid/random search
Permutation testsStatistical significanceNon-parametric testing
Neural architecture searchArchitecture combinationsNAS search space
import numpy as np
from math import factorial

# Hyperparameter search space
n_lr = 5  # learning rates to try
n_layers = 4  # layer depths to try
n_units = 3  # unit sizes to try

total_combinations = n_lr * n_layers * n_units
print(f"Grid search space: {n_lr} × {n_layers} × {n_units} = {total_combinations} combinations")

# Permutation test for significance
np.random.seed(42)
group_a = np.random.normal(50, 10, 30)
group_b = np.random.normal(55, 10, 30)
observed_diff = group_b.mean() - group_a.mean()

# Random permutations
n_perms = 10000
combined = np.concatenate([group_a, group_b])
count = 0
for _ in range(n_perms):
    np.random.shuffle(combined)
    perm_diff = combined[:30].mean() - combined[30:].mean()
    if perm_diff >= observed_diff:
        count += 1

p_value = count / n_perms
print(f"\nObserved difference: {observed_diff:.2f}")
print(f"Permutation p-value: {p_value:.4f}")
print(f"Significant: {'Yes' if p_value < 0.05 else 'No'}")

Key Takeaways

Summary: Counting Principles

  • Multiplication principle: total ways = product of choices for each independent task
  • Factorial (n!) = product of all integers from 1 to n — counts arrangements
  • Permutations P(n,r) = n!/(n-r)! — ordered arrangements of r from n
  • Combinations C(n,r) = n!/(r!(n-r)!) — unordered selections of r from n
  • Order matters -> permutations; order doesn't -> combinations
  • Python tools: math.factorial(), math.perm(), math.comb(), itertools.permutations(), itertools.combinations()

Premium Content

Counting Principles — Permutations and Combinations

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement