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.
Chapters
- 01Basic Principles of CountingLecture 5.1
- 02The Multiplication RuleLecture 5.1
- 03FactorialsLectures 5.1 and 5.2
- 04Week 5 Summary SheetAll lectures
Based on lectures by Usha Mohan, IIT Madras
Basic Principles of Counting
The learning goals of the week and the addition rule: "or" means add.
1.1What you will learn this week
- 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.
- 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
If you must do one thing or another (you cannot do both), count the ways for each and add.
If an action A can occur in different ways and another action B can occur in different ways, then the total number of ways for A or B to occur is
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?
- There are 4 choices for a shirt.
- There are 3 choices for a pant.
- If you buy a shirt you cannot buy a pant (and the other way round), so the two cases never overlap.
- Total = 4 + 3 = 7.
- Answer: 7 ways.
1.3Going deeper
- 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.
- 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.
- Spotting it. Words like "either", "or", "one of" usually signal the addition rule.
- Ask: can both happen at once? If not, and the question is "A or B", add.
- Check that every outcome is counted exactly once.
- Multiplying for an "or" question (4 × 3 = 12 instead of 7).
- Adding groups that overlap, so some outcomes are counted twice.
The Multiplication Rule
"And" means multiply: matching outfits, tree diagrams and counting passwords.
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:
| Shirt | Pant | Set |
|---|---|---|
| Yellow | Black | Yellow + Black |
| Yellow | Blue | Yellow + Blue |
| Yellow | Brown | Yellow + Brown |
| Blue | Black | Blue + Black |
| Blue | Blue | Blue + Blue |
| Blue | Brown | Blue + Brown |
| Green | Black | Green + Black |
| Green | Blue | Green + Blue |
| Green | Brown | Green + Brown |
| Orange | Black | Orange + Black |
| Orange | Blue | Orange + Blue |
| Orange | Brown | Orange + Brown |
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?
- Choose the shirt: 4 ways.
- For each shirt, choose the pant: 3 ways.
- Total = 4 × 3 = 12.
- Answer: 12 sets.
2.2The multiplication rule
If action A can occur in ways and action B in ways, then A and B together can occur in ways. More generally, if actions are performed in a definite order, with possibilities for the first action and, for each of these, for the second, and so on, then there are
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).
Example 3: shirt, pant and shoes
How many outfits of one shirt, one pant and one pair of shoes are there?
- Each box in Figure 3 is one action in order, and the number inside is how many ways it can be done.
- The 12 shirt–pant sets can each go with a black shoe (12 ways) or a brown shoe (12 ways): 12 + 12 = 24.
- 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.
- Answer: 24 outfits.
2.4Which rule: add or multiply?
| Words in the problem | Rule | Result |
|---|---|---|
| A or B (choose one of the two kinds) | Addition | |
| A and B (do both, in order) | Multiplication |
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.
- (a) Repetition allowed. Each letter place has 26 choices and each digit place has 10.
- (b) No repetition. Letters: 26, then 25. Digits: 10, then 9, then 8, then 7.
- Answer: (a) 6,760,000 (b) 3,276,000.
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
- Repetition allowed: a power (extra remark). If every one of positions has the same choices, the count is . The password in (a) is .
- No repetition: a falling product. From one pool of , the choices go . Letters and digits are two separate pools, so each pool starts afresh: 26, 25 for letters and 10, 9, 8, 7 for digits.
- 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: .
- 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.
- 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.
- 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.
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)?
- First place: any of the 8 athletes.
- Second place: any of the remaining 7, and so on.
- Seventh place: any of the remaining 2; the last place goes to the only one left (1).
- Total = 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 40,320.
- Answer: 40,320 ways.
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
The product of the first positive integers is called n factorial, written .
3.3Factorial table
| n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| n! | 1 | 1 | 2 | 6 | 24 | 120 | 720 | 5,040 | 40,320 | 362,880 | 3,628,800 |
This table is computed from the definition; it is not on the lecture slides. Factorials grow very fast: , and already has 19 digits.
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?
- First place: 3 choices, second: 2, third: 1.
- Total = 3 × 2 × 1 = 3! = 6.
- The six orders are listed in Figure 7.
- Answer: 6 = 3!.
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
| Property | Example |
|---|---|
| for |
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!.
- Answer: 120.
Example 8: simplifying expressions
Simplify (1) ; (2) ; (3) express using factorials.
- , which is 13,800.
- Answer: (1) 120 (2) 600 (3) 25!/22!.
3.6Going deeper
- The last r factors (extra remark). The product of the top numbers from downwards is . Example 8 (3) is the case . The race of Example 5 is the case : . This is the counting of the next lectures (with order).
- Factorials do not split over + or ×. and . For example but , and neither equals .
- Cancel, do not compute. without ever computing 100!.
- Expand the larger factorial only down to the smaller one.
- Learn the table up to 7! (5,040); it saves time.
- Taking ; it is 1.
- Writing ; factorials do not divide like that (the answer is 120).
- Writing .
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
| Idea | Rule | Example |
|---|---|---|
| Addition rule (A or B, not both) | 4 shirts or 3 pants: 7 | |
| Multiplication rule (A and B) | 4 × 3 = 12; with 2 shoes: 24 | |
| Password, repetition allowed | 6,760,000 | |
| Password, no repetition | 3,276,000 | |
| Factorial | , | 8! = 40,320 finishes |
| Recursion | 5! = 5 × 4! | |
| Cut a factorial | 25 × 24 × 23 = 25!/22! | |
| Arrangements in a row | n different objects: ways | 3 shirts: 3! = 6 |
Formula sheet at a glance
Formulas
Use whenYou choose one option from separate groups.
- Check that the groups cannot overlap.
- Count each group.
- Add the counts.
Use whenYou make several choices one after another.
- Draw one blank per choice.
- Write the number of options in each blank.
- Multiply.
Use whenFilling positions from a pool (letters, digits).
- Allowed: every blank of a pool has the full count.
- Not allowed: one fewer each time within the pool.
- Separate pools start afresh.
Use whenYou arrange n different objects in a row, or fill every place from n.
- Start at n.
- Multiply by every whole number down to 1.
- Use the table for small n.
Use whenA fraction has factorials on top and bottom.
- Expand the bigger factorial down to the smaller one.
- Cancel the common factorial.
- Multiply what is left.
Quick factorial table
| n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| n! | 1 | 1 | 2 | 6 | 24 | 120 | 720 | 5,040 | 40,320 |
How to decide
- Read the problem: is it "or" (one of several kinds) or "and" (several choices in order)?
- Draw a blank for each choice and write the number of options in it.
- Add for "or", multiply for "and"; reduce the options by one each time if repetition is not allowed.
- If you fill every place from a set of n different objects, the answer is n!.
n1 + n2
4 shirts or 3 pants: 7
n1 × n2 × … × nr
4 × 3 × 2 = 24
None: 26 × 25 × 10 × 9 × 8 × 7
Separate pools
0! = 1
8! = 40,320
3 shirts: 6
Expand the bigger, cancel
6!/3! = 120