Weeks
Statistics 1Week 5 · Counting: Basic Principles and Factorials
Week 5 Notes

Statistics for
Data Science 1

Counting: the addition and multiplication rules, tree diagrams, counting codes with and without repetition, and factorials with the tricks for simplifying them.

4 chapters~13 min read
Addition ruleMultiplication ruleTree diagramsFactorials

Chapters

  1. 01Basic Principles of CountingLecture 5.1
  2. 02The Multiplication RuleLecture 5.1
  3. 03FactorialsLectures 5.1 and 5.2
  4. 04Week 5 Summary SheetAll lectures

Based on lectures by Usha Mohan, IIT Madras

01
Lecture 5.1

Basic Principles of Counting

The learning goals of the week and the addition rule: "or" means add.

1.1What you will learn this week

Learning objectives
  • Understand the basic principles of counting.
  • The concept of factorials.
  • The difference between counting with order (permutation) and without regard to order (combination).
  • Use permutations and combinations in real-life applications.
Covered here
  • Lectures 5.1 and 5.2: the counting rules and factorials (the first two objectives).
  • Permutations and combinations come next; they are built from this week's multiplication rule and factorials.

Counting is the base of probability later in the course: to find a chance you often have to count how many outcomes are possible and how many of them are favourable.

1.2The addition rule of counting

In simple words

If you must do one thing or another (you cannot do both), count the ways for each and add.

Definition: addition rule

If an action A can occur in n1n_1 different ways and another action B can occur in n2n_2 different ways, then the total number of ways for A or B to occur is

n1+n2n_1 + n_2
4 shirtsS1S2S3S4+3 pantsP1P2P3=7wayspick one item from either box
Figure 1. Gift card: one shirt or one pant

Left box: the 4 shirt choices. Right box: the 3 pant choices. You pick from one box only, so the choices add up to 4 + 3 = 7.

Example 1: buying clothes (or)

A gift card lets you buy one item, either a shirt or a pant. The retailer has 4 shirts and 3 pants. In how many different ways can you use the card?

  1. There are 4 choices for a shirt.
  2. There are 3 choices for a pant.
  3. If you buy a shirt you cannot buy a pant (and the other way round), so the two cases never overlap.
  4. Total = 4 + 3 = 7.
  5. Answer: 7 ways.
Watch out. The addition rule is for actions that cannot happen together: either the shirt case or the pant case, never both.

1.3Going deeper

  1. More than two options (extra remark). The rule extends to any number of non-overlapping options: 4 shirts or 3 pants or 2 caps gives 4 + 3 + 2 = 9 ways.
  2. Why "cannot both" matters (extra remark). Suppose 5 students are in the music club and 4 in the dance club, and 2 of them are in both. Choosing one student from either club does not give 5 + 4 = 9: the 2 students in both clubs were counted twice. The correct count is 5 + 4 − 2 = 7. The addition rule as stated needs the two groups to be separate.
  3. Spotting it. Words like "either", "or", "one of" usually signal the addition rule.
Exam tips
  • Ask: can both happen at once? If not, and the question is "A or B", add.
  • Check that every outcome is counted exactly once.
Common mistakes
  • Multiplying for an "or" question (4 × 3 = 12 instead of 7).
  • Adding groups that overlap, so some outcomes are counted twice.
Next · Lecture 5.1The Multiplication Rule
02
Lecture 5.1

The Multiplication Rule

"And" means multiply: matching outfits, tree diagrams and counting passwords.

In simple words

If you must do one thing and then another, the choices multiply. Each choice of the first action can be paired with every choice of the second.

2.1Matching shirts and pants

Now the card lets you buy one shirt and one pant. With 4 shirts and 3 pants, how many sets can we make? Each shirt matches with each of the 3 pants:

ShirtPantSet
YellowBlackYellow + Black
YellowBlueYellow + Blue
YellowBrownYellow + Brown
BlueBlackBlue + Black
BlueBlueBlue + Blue
BlueBrownBlue + Brown
GreenBlackGreen + Black
GreenBlueGreen + Blue
GreenBrownGreen + Brown
OrangeBlackOrange + Black
OrangeBlueOrange + Blue
OrangeBrownOrange + Brown
shirt (4 ways)pant (3 ways)12 setsYellowBlackYellow + BlackBlueYellow + BlueBrownYellow + BrownBlueBlackBlue + BlackBlueBlue + BlueBrownBlue + BrownGreenBlackGreen + BlackBlueGreen + BlueBrownGreen + BrownOrangeBlackOrange + BlackBlueOrange + BlueBrownOrange + Brown
Figure 2. Tree: every shirt branches into all 3 pants

Read the tree from left to right: pick a shirt (4 ways), then a pant (3 ways). The last column lists all 12 sets. Each of the 4 shirts opens 3 branches: 3 + 3 + 3 + 3 = 4 × 3 = 12.

Example 2: matching shirts and pants (and)

The card now allows one shirt and one pant. There are 4 shirts and 3 pants. How many sets can you make?

  1. Choose the shirt: 4 ways.
  2. For each shirt, choose the pant: 3 ways.
  3. Total = 4 × 3 = 12.
  4. Answer: 12 sets.

2.2The multiplication rule

Definition: multiplication rule

If action A can occur in n1n_1 ways and action B in n2n_2 ways, then A and B together can occur in n1×n2n_1 \times n_2 ways. More generally, if rr actions are performed in a definite order, with n1n_1 possibilities for the first action and, for each of these, n2n_2 for the second, and so on, then there are

n1×n2×⋯×nrn_1 \times n_2 \times \cdots \times n_r

possibilities altogether.

2.3Adding shoes: three actions

Now the card allows a shirt, a pant and a pair of shoes. There are 2 kinds of shoes (black and brown).

4 shirtsfirst choice×3 pantssecond choice×2 shoesthird choice=24
Figure 3. Three actions in order, one product

Example 3: shirt, pant and shoes

How many outfits of one shirt, one pant and one pair of shoes are there?

  1. Each box in Figure 3 is one action in order, and the number inside is how many ways it can be done.
  2. The 12 shirt–pant sets can each go with a black shoe (12 ways) or a brown shoe (12 ways): 12 + 12 = 24.
  3. This is the same as 4 × 3 × 2 = 24. The lecture's tree for this case has 24 end points: 4 shirts, 3 pants each, 2 shoes each.
  4. Answer: 24 outfits.

2.4Which rule: add or multiply?

Words in the problemRuleResult
A or B (choose one of the two kinds)Additionn1+n2n_1 + n_2
A and B (do both, in order)Multiplicationn1×n2×⋯n_1 \times n_2 \times \cdots

2.5Creating an alpha-numeric code

Example 4: a six-character password

Create a six-character password: the first two characters are letters, followed by four numbers (digits). Count the passwords if (a) repetition is allowed, (b) repetition is not allowed.

  1. (a) Repetition allowed. Each letter place has 26 choices and each digit place has 10.
  2. 26×26×10×10×10×10=6,760,00026 \times 26 \times 10 \times 10 \times 10 \times 10 = 6{,}760{,}000
  3. (b) No repetition. Letters: 26, then 25. Digits: 10, then 9, then 8, then 7.
  4. 26×25×10×9×8×7=3,276,00026 \times 25 \times 10 \times 9 \times 8 \times 7 = 3{,}276{,}000
  5. Answer: (a) 6,760,000 (b) 3,276,000.
(a) repetition allowed26×26×10×10×10×10= 6,760,000(b) no repetition26×25×10×9×8×7= 3,276,000lettersdigits
Figure 4. One blank for every position, with the number of choices written in it
Trick

Draw one blank for every position. Write the number of choices in each blank. If repetition is not allowed, the count drops by 1 each time you pick from the same pool.

2.6Going deeper

  1. Repetition allowed: a power (extra remark). If every one of rr positions has the same nn choices, the count is nrn^r. The password in (a) is 262×10426^2 \times 10^4.
  2. No repetition: a falling product. From one pool of nn, the choices go n,n−1,n−2,…n, n-1, n-2, \ldots. Letters and digits are two separate pools, so each pool starts afresh: 26, 25 for letters and 10, 9, 8, 7 for digits.
  3. Both rules together (extra remark). A code that is either 2 letters or 3 digits (repetition allowed): each kind is a product, and "either" adds them: 262+103=676+1000=167626^2 + 10^3 = 676 + 1000 = 1676.
  4. Why the tree helps. A tree lists every outcome, so it is a check for small cases; the number of leaves always equals the product.
Exam tips
  • Underline "and" / "or" in the question before calculating.
  • Draw the blanks; then multiply the numbers written in them.
  • Without repetition, reduce by one only within the same pool.
Common mistakes
  • Adding for an "and" question (4 + 3 + 2 = 9 instead of 24).
  • Reducing the digits because a letter was used (the pools are separate).
  • Forgetting that 0 is one of the 10 digits.
Next · Lectures 5.1 and 5.2Factorials
03
Lectures 5.1 and 5.2

Factorials

Where n! comes from, its definition, the table, arranging objects in a row, and simplifying fractions of factorials.

3.1Where factorials come from

Example 5: order of finishes in a race

Eight athletes run a 100 m race. In how many ways can they finish (no ties)?

  1. First place: any of the 8 athletes.
  2. Second place: any of the remaining 7, and so on.
  3. Seventh place: any of the remaining 2; the last place goes to the only one left (1).
  4. Total = 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 40,320.
  5. Answer: 40,320 ways.
8place 17place 26place 35place 44place 53place 62place 71place 8
Figure 5. Filling the 8 finishing places

Each box is a finishing place and the number inside is how many athletes can still fill it: 8, then 7, then 6, down to 1. This product of all whole numbers from 8 down to 1 has a name.

3.2Definition

Definition: n factorial

The product of the first nn positive integers is called n factorial, written n!n!.

n!=n×(n−1)×⋯×1,0!=1n! = n \times (n - 1) \times \cdots \times 1, \qquad 0! = 1
Why 0! = 1 (extra remark). The convention keeps the rule n!=n×(n−1)!n! = n \times (n-1)! true for n=1n = 1: 1!=1×0!1! = 1 \times 0!, and since 1!=11! = 1, 0!0! must be 1. It also matches counting: there is exactly one way to arrange nothing.

3.3Factorial table

n012345678910
n!1126241207205,04040,320362,8803,628,800

This table is computed from the definition; it is not on the lecture slides. Factorials grow very fast: 12!=479,001,60012! = 479{,}001{,}600, and 20!20! already has 19 digits.

n! grows very fast (log scale)1122364245120672075,040840,3209363K103.6M1139.9M12479.0Mn
Figure 6. n! for n = 1 to 12; each step multiplies by the next number

3.4Arranging objects in a row

Example 6: arranging shirts

You have 3 shirts: yellow, blue and green. In how many different orders can you arrange them in a row?

  1. First place: 3 choices, second: 2, third: 1.
  2. Total = 3 × 2 × 1 = 3! = 6.
  3. The six orders are listed in Figure 7.
  4. Answer: 6 = 3!.
1.YBG2.YGB3.BYG4.BGY5.GYB6.GBY
Figure 7. The 6 orders of 3 different shirts (Y = yellow, B = blue, G = green)
Rule

n different objects can be arranged in a row in n! ways: n choices for the first place, n − 1 for the second, and so on.

3.5Useful properties

PropertyExample
n!=n×(n−1)!n! = n \times (n-1)!5!=5×4!=1205! = 5 \times 4! = 120
n!=n×(n−1)×⋯×(n−i+1)×(n−i)!n! = n \times (n-1) \times \cdots \times (n-i+1) \times (n-i)! for i≤ni \le n5!=5×4×3!5! = 5 \times 4 \times 3!
The cancelling trick

To simplify a fraction of factorials, expand the bigger factorial only until it reaches the smaller one, then cancel.

Example 7: expanding 5!

(1) Compute 5!. (2) Write 5! using 4!. (3) Write 5! using 3!.

  1. 5!=5×4×3×2×1=1205! = 5 \times 4 \times 3 \times 2 \times 1 = 120
  2. 5!=5×4!5! = 5 \times 4!
  3. 5!=5×4!=5×4×3!5! = 5 \times 4! = 5 \times 4 \times 3!
  4. Answer: 120.

Example 8: simplifying expressions

Simplify (1) 6!3!\dfrac{6!}{3!}; (2) 6!×5!3!×4!\dfrac{6! \times 5!}{3! \times 4!}; (3) express 25×24×2325 \times 24 \times 23 using factorials.

  1. 6!3!=6×5×4×3!3!=6×5×4=120\dfrac{6!}{3!} = \dfrac{6 \times 5 \times 4 \times 3!}{3!} = 6 \times 5 \times 4 = 120
  2. 6!×5!3!×4!=6×5×4×3!3!×5×4!4!=120×5=600\dfrac{6! \times 5!}{3! \times 4!} = \dfrac{6 \times 5 \times 4 \times 3!}{3!} \times \dfrac{5 \times 4!}{4!} = 120 \times 5 = 600
  3. 25×24×23=25×24×23×22!22!=25!22!25 \times 24 \times 23 = \dfrac{25 \times 24 \times 23 \times 22!}{22!} = \dfrac{25!}{22!}, which is 13,800.
  4. Answer: (1) 120 (2) 600 (3) 25!/22!.
6! / 3!654321321cancel the common 3!6 × 5 × 4 = 120
Figure 8. 6!/3!: write 6! down to 3!, then the 3! cancels

3.6Going deeper

  1. The last r factors (extra remark). The product of the top rr numbers from nn downwards is n!(n−r)!\dfrac{n!}{(n-r)!}. Example 8 (3) is the case n=25,r=3n = 25, r = 3. The race of Example 5 is the case r=nr = n: 8!0!=8!\dfrac{8!}{0!} = 8!. This is the counting of the next lectures (with order).
  2. Factorials do not split over + or ×. (a+b)!≠a!+b!(a+b)! \ne a! + b! and (a×b)!≠a!×b!(a \times b)! \ne a! \times b!. For example 4!×3!=1444! \times 3! = 144 but 4!+3!=304! + 3! = 30, and neither equals 7!=50407! = 5040.
  3. Cancel, do not compute. 100!98!=100×99=9900\dfrac{100!}{98!} = 100 \times 99 = 9900 without ever computing 100!.
Exam tips
  • Expand the larger factorial only down to the smaller one.
  • Learn the table up to 7! (5,040); it saves time.
Common mistakes
  • Taking 0!=00! = 0; it is 1.
  • Writing 6!3!=2!\dfrac{6!}{3!} = 2!; factorials do not divide like that (the answer is 120).
  • Writing (a+b)!=a!+b!(a+b)! = a! + b!.
Next · All lecturesWeek 5 Summary Sheet
04
All lectures

Week 5 Summary Sheet

Everything in Week 5 on one sheet.

Lectures 5.1 and 5.2 on one sheet, for a last-minute revision.

The week in one table

IdeaRuleExample
Addition rule (A or B, not both)n1+n2n_1 + n_24 shirts or 3 pants: 7
Multiplication rule (A and B)n1×n2×⋯×nrn_1 \times n_2 \times \cdots \times n_r4 × 3 = 12; with 2 shoes: 24
Password, repetition allowed26×26×10426 \times 26 \times 10^46,760,000
Password, no repetition26×25×10×9×8×726 \times 25 \times 10 \times 9 \times 8 \times 73,276,000
Factorialn!=n×(n−1)×⋯×1n! = n \times (n-1) \times \cdots \times 1, 0!=10! = 18! = 40,320 finishes
Recursionn!=n×(n−1)!n! = n \times (n-1)!5! = 5 × 4!
Cut a factorialn!=n(n−1)⋯(n−i+1)×(n−i)!n! = n(n-1)\cdots(n-i+1) \times (n-i)!25 × 24 × 23 = 25!/22!
Arrangements in a rown different objects: n!n! ways3 shirts: 3! = 6

Formula sheet at a glance

Counting rules
Addition rule (or)n1+n2n_1 + n_2
Multiplication rule (and)n1×n2×⋯×nrn_1 \times n_2 \times \cdots \times n_r
Repetition
r positions, n choices eachnrn^r
No repetition, one pooln×(n−1)×⋯n \times (n-1) \times \cdots
Factorials
Definitionn!=n×(n−1)×⋯×1n! = n \times (n-1) \times \cdots \times 1
Convention0!=10! = 1
Recursionn!=n×(n−1)!n! = n \times (n-1)!
Simplifying
Top r factorsn!(n−r)!=n(n−1)⋯(n−r+1)\frac{n!}{(n-r)!} = n(n-1)\cdots(n-r+1)

Formulas

Addition rule
A or B, never bothn1+n2n_1 + n_2

Use whenYou choose one option from separate groups.

  1. Check that the groups cannot overlap.
  2. Count each group.
  3. Add the counts.
Example4 shirts or 3 pants.
4+3=74 + 3 = 7
Multiplication rule
A and then Bn1×n2n_1 \times n_2
r actions in ordern1×n2×⋯×nrn_1 \times n_2 \times \cdots \times n_r

Use whenYou make several choices one after another.

  1. Draw one blank per choice.
  2. Write the number of options in each blank.
  3. Multiply.
ExampleA shirt, a pant and shoes.
4×3×2=244 \times 3 \times 2 = 24
With and without repetition
Repetition allowednrn^r
No repetitionn(n−1)(n−2)⋯n(n-1)(n-2)\cdots

Use whenFilling positions from a pool (letters, digits).

  1. Allowed: every blank of a pool has the full count.
  2. Not allowed: one fewer each time within the pool.
  3. Separate pools start afresh.
ExampleTwo letters and four digits.
262×104=6,760,00026⋅25⋅10⋅9⋅8⋅7=3,276,000\begin{gathered} 26^2 \times 10^4 = 6{,}760{,}000 \\[6pt] 26 \cdot 25 \cdot 10 \cdot 9 \cdot 8 \cdot 7 = 3{,}276{,}000 \end{gathered}
Factorial
Definitionn!=n×(n−1)×⋯×1n! = n \times (n-1) \times \cdots \times 1
Convention0!=10! = 1

Use whenYou arrange n different objects in a row, or fill every place from n.

  1. Start at n.
  2. Multiply by every whole number down to 1.
  3. Use the table for small n.
ExampleEight runners in a race.
8!=40,3208! = 40{,}320
Simplifying factorials
Recursionn!=n×(n−1)!n! = n \times (n-1)!
Top r factorsn!(n−r)!\frac{n!}{(n-r)!}

Use whenA fraction has factorials on top and bottom.

  1. Expand the bigger factorial down to the smaller one.
  2. Cancel the common factorial.
  3. Multiply what is left.
ExampleExample 8 (2).
6!×5!3!×4!=(6⋅5⋅4)(5)=600\frac{6! \times 5!}{3! \times 4!} = (6 \cdot 5 \cdot 4)(5) = 600

Quick factorial table

n012345678
n!1126241207205,04040,320

How to decide

  1. Read the problem: is it "or" (one of several kinds) or "and" (several choices in order)?
  2. Draw a blank for each choice and write the number of options in it.
  3. Add for "or", multiply for "and"; reduce the options by one each time if repetition is not allowed.
  4. If you fill every place from a set of n different objects, the answer is n!.
Coming nextThe lectures introduce counting with order (permutations) and without order (combinations). They build on the multiplication rule and factorials from this week.
Source notesLecture 5.2 repeats the factorial part of 5.1 (race example, definition, examples), so both are merged into Chapter 3. The source's extra practice questions are not reproduced, as the Statistics 1 notes carry worked examples only.
Revision overview
Addition ruleA or B, never both
n1 + n2
4 shirts or 3 pants: 7
Multiplication ruleA and then B
n1 × n2 × … × nr
4 × 3 × 2 = 24
CodesRepetition: 26 × 26 × 10^4
None: 26 × 25 × 10 × 9 × 8 × 7
Separate pools
CountingStatistics for Data Science 1
Factorialn! = n × (n − 1) × … × 1
0! = 1
8! = 40,320
Arrangementsn objects in a row: n!
3 shirts: 6
Simplifyingn! = n × (n − 1)!
Expand the bigger, cancel
6!/3! = 120
Revision: the whole of Week 5 on one map
Back to top