counting - github pages · theruleofproduct theruleofsum finitesets overcounting subtractionrule...

54
Counting

Upload: others

Post on 21-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

Counting

Page 2: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 2

What canwe count?

• In how many ways can we paint 6 rooms, choosing from 15available colors?

• What if we want all rooms painted with different colors?

• In how many different ways 10 books can be arranged on ashelf?

• What if 2 of those 10 books are identical copies?

Page 3: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 3

1, 2, 5, 14, . . .

Page 4: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 4

1, 2, 5, 14, . . .

Page 5: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 5

Problem

The chairs of an auditorium are to be labeled with an uppercase

letter followed by a positive integer not exceeding 100. What is

the largest number of chairs that can be labeled differently?

A-1, A-2, . . . Z-100

There are

1. 26 ways to assign a letter and

2. 100 ways to assign a number.

26 · 100

Page 6: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 6

Problem

The chairs of an auditorium are to be labeled with an uppercase

letter followed by a positive integer not exceeding 100. What is

the largest number of chairs that can be labeled differently?

A-1, A-2, . . . Z-100

There are

1. 26 ways to assign a letter and

2. 100 ways to assign a number.26 · 100

Page 7: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 7

The Rule of Product

There are

1. 26 ways to assign a letter and

2. 100 ways to assign a number.

26 · 100

The Rule of Product. Suppose that a procedure can be broken downinto a sequence of two tasks. If there are n1 ways to do the firsttask and for each of these ways of doing the first task, there aren2 ways to do the second task, then there are n1n2 ways to do theprocedure.

Page 8: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 8

Chairs again

Consider the same problem about the labels for chairs

1. 26 ways to choose a letter and

2. 100 ways to choose a number.

Write a program that prints all 2600 labels?

for a := A to Z dofor n := 1 to 100 do

print_label(a, n)

Page 9: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 9

Chairs again

Consider the same problem about the labels for chairs

1. 26 ways to choose a letter and

2. 100 ways to choose a number.

Write a program that prints all 2600 labels?

for a := A to Z dofor n := 1 to 100 do

print_label(a, n)

Page 10: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 10

Generalized Product Rule

If a procedure consists of k sub-tasks, and the sub-tasks can be per-formed in n1, . . . , nk ways, then the procedure can be performed

in (n1 · n2 · . . . · nk) ways.

Example:Count the number of different bit strings of length seven.

Page 11: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 11

Generalized Product Rule

If a procedure consists of k sub-tasks, and the sub-tasks can be per-formed in n1, . . . , nk ways, then the procedure can be performed

in (n1 · n2 · . . . · nk) ways.

Example:Count the number of different bit strings of length seven.

The value for each bit can be chosen in two ways (0 or 1). There-fore:

2 · 2 · 2 · 2 · 2 · 2 · 2= 27 = 128

Page 12: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 12

License plates

How many different license plates of this format can be made?

11, 1

Page 13: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 13

License plates

How many different license plates of this format can be made?

263 · 104 = 175,760, 000

Page 14: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 14

Another counting problem

A college library has 40 books on sociology and 50 books on an-thropology.

You have to choose only one book from the library. In how manyways can it be done?

Page 15: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 15

Another counting problem

A college library has 40 books on sociology and 50 books on an-thropology.

You have to choose only one book from the library. In how manyways can it be done?

40+ 50= 90 this is called the rule of sum

Page 16: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 16

The Rule of Sum

40 books on sociology, and 50 books on anthropology.There are 40+ 50= 90 ways to choose a book.

Write an algorithm for a robot to read all the books in the library:

for b := 1 to 40 doread(Sociology, b)

for b := 1 to 50 doread(Anthropology, b)

Page 17: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 17

The Rule of Sum

40 books on sociology, and 50 books on anthropology.There are 40+ 50= 90 ways to choose a book.

Write an algorithm for a robot to read all the books in the library:

for b := 1 to 40 doread(Sociology, b)

for b := 1 to 50 doread(Anthropology, b)

Page 18: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 18

The Rule of Sum

40 books on sociology, and 50 books on anthropology.There are 40+ 50= 90 ways to choose a book.

The Rule of Sum. If a task can be done either in one of n1 ways orin one of n2 ways, where none of the set of n1 ways is the same asany of the set of n2 ways, then there are n1+n2 ways to do the task.

Note that it’s important that the two groups don’t have commonelements (We say that they are disjoint sets).

Page 19: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 19

Problem

You have 3 textbooks, 5 novels, 4 magazines, and 2 comic books.

You want to pick only one book to read in the subway. How manyoptions do you have?

Page 20: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 20

Problem

You have 3 textbooks, 5 novels, 4 magazines, and 2 comic books.

You want to pick only one book to read in the subway. How manyoptions do you have?

3+ 5+ 4+ 2= 14.

Page 21: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 21

Problem

NYS whats to change the license plates format, allowing

3 letters + 3 digits; 2 letters + 2 digits; and 1 letter + 1 digit.

AAA 111AA 11

A 1

How many license plates can be made?

Page 22: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 22

Problem

NYS whats to change the license plates format, allowing

up to 3 letters followed by up to 3 digits.

A 1 A 11 A 111AA 1 AA 11 AA 111

AAA 1 AAA 11 AAA 111

How many license plates can be made?

Page 23: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 23

A new objectDef. A set is an unordered collection of objects. The objects arecalled elements.

If e is an element of the set A, we write e ∈ A.

Otherwise, if it’s not in A, we write e /∈ A.

Example:A= {1,2, 97,3, 15}.

1 ∈ A.

4 /∈ A.

{1,2, 3,3, 2,1, 1,1, 1}= {1, 2,3}

Page 24: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 24

Sets

Page 25: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 25

Some important sets

Natural numbersN= {0, 1, 2, 3, . . .}

Integer numbers

Z= {. . . , −3, −2, −1, 0, 1, 2, 3, . . .}

Empty set∅= { }

Page 26: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 26

Set Builder NotationWe can describe sets using predicates:

A= {x | P(x)}

“Set A is such that x ∈ A if and only if P(x).”

Example. Positive integers:

Z+ =�

n ∈ Z | n> 0

= {1, 2,3, . . .}

More complex predicates are fine too. Odd and even numbers:

Even=�

n ∈ Z | ∃k ∈ Z (n= 2k)

Odd =�

n ∈ Z | ∃k ∈ Z (n= 2k+ 1)

Page 27: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 27

Union,∪

A∪ B denotes all things that are members of either A or B:

A∪ B = {x | (x ∈ A)∨ (x ∈ B)}

Equivalently:

x belongs to A∪ B if and only if x ∈ A or x ∈ B.

Examples:

{1, 2} ∪ {‘a’, ‘b’}= {1, 2, ‘a’, ‘b’}{1, 2, 3} ∪ {2, 3, 5}= {1, 2, 3, 5}

Page 28: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 28

Intersection,∩A∩ B denotes all things that are members of both A and B:

A∩ B = {x | (x ∈ A)∧ (x ∈ B)}

Equivalently:

x belongs to A∩ B if and only if x ∈ A and x ∈ B.

Examples:

{1, 2} ∩ {‘a’, ‘b’}=∅{1, 2, 3} ∩ {2, 3, 5}= {2, 3}

Sets A and B are called disjoint if their intersection is empty:A∩ B =∅.

Page 29: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 29

Numberof theelementsof afinite set

Def. If set A is finite, and there are exactly n elements in S, then n

is the cardinality of the set A. We write

|A|= n.

Examples:

A= {3, 4, 5, 6}|A|= 4

B =�

{3, 4}, {5, 6}, 7

|B|= 3

|∅|= 0

Page 30: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 30

Question

A= {1, 2, 4, 5}

B = {20, 21, 22, 23, 24}

A∪ B = {1, 2, 4, 5, 20, 21, 22, 23, 24}

If two sets are disjoint (their intersection is empty), what is thecardinality if their union?

|A∪ B|= 9, and |A|+ |B|= 4+ 5= 9.

|A∪ B|= |A|+ |B|= 4+ 5= 9.

Page 31: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 31

Question

A= {1, 2, 4, 5}

B = {20, 21, 22, 23, 24}

A∪ B = {1, 2, 4, 5, 20, 21, 22, 23, 24}

If two sets are disjoint (their intersection is empty), what is thecardinality if their union?

|A∪ B|= 9, and |A|+ |B|= 4+ 5= 9.

|A∪ B|= |A|+ |B|= 4+ 5= 9.

Page 32: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 32

Question

You are given k disjoint sets A1, . . . Ak:

It means that Ai ∩ A j =∅ when i 6= j.

What is the cardinality if their union A1 ∪ . . .∪ Ak?

|A1 ∪ . . .∪ Ak|= |A1|+ . . .+ |Ak|=k∑

i=1

|Ai|.

This is the same sum rule for counting

Page 33: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 33

Question

You are given k disjoint sets A1, . . . Ak:

It means that Ai ∩ A j =∅ when i 6= j.

What is the cardinality if their union A1 ∪ . . .∪ Ak?

|A1 ∪ . . .∪ Ak|= |A1|+ . . .+ |Ak|=k∑

i=1

|Ai|.

This is the same rule of sum, right?

Page 34: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 34

Question

You are given k disjoint sets A1, . . . Ak:

It means that Ai ∩ A j =∅ when i 6= j.

What is the cardinality if their union A1 ∪ . . .∪ Ak?

|A1 ∪ . . .∪ Ak|= |A1|+ . . .+ |Ak|=k∑

i=1

|Ai|.

This is the same rule of sum, right?

Page 35: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 35

Question

Why do we insist on the sets being disjoint?

Really, who cares?

Page 36: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 36

Because

A= {1, 2, 3}

B = {3, 4}

Their union: A∪ B = {1, 2, 3, 4}

|A|+ |B|=�

�{1, 2 ,3}�

�+�

�{3, 4}�

�= 3+ 2= 5

|A∪ B|=�

�{1, 2, 3, 4}�

�= 4

So, in general, |A∪ B| 6= |A|+ |B|, and if we try to use the sum rulewhen the sets are not disjoint, we overcount, and this is really bad.

Page 37: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 37

Overcounting

A= {1, 2, 3}

B = {3, 4}

A∪ B = {1, 2, 3, 4}

We were overcounting, because the common elements of A and Bwere counted twice:

|A|+ |B|=�

�{1, 2, 3}�

�+�

�{3, 4}�

�= 5,

|A∪ B|=�

�{1, 2, 3, 4}�

�= 4.

Therefore, to get the correct value of |A∪ B|, the number of commonelements must be subtracted:

|A∪ B|= |A|+ |B| −�

�{3}�

�= 3+ 2− 1= 4

Page 38: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 38

Overcounting

A= {1, 2, 3}

B = {3, 4}

A∪ B = {1, 2, 3, 4}

We were overcounting, because the common elements of A and Bwere counted twice:

|A|+ |B|=�

�{1, 2, 3}�

�+�

�{3, 4}�

�= 5,

|A∪ B|=�

�{1, 2, 3, 4}�

�= 4.

Therefore, to get the correct value of |A∪B|, the number of commonelements must be subtracted:

|A∪ B|= |A|+ |B| −�

�{3}�

�= 3+ 2− 1= 4.

Page 39: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 39

The Subtraction Rule

A= {1, 2, 3}

B = {3, 4}

A∪ B = {1, 2, 3, 4}

Therefore, to get the correct value of |A∪B|, the number of commonelements must be subtracted:

|A∪ B|= |A|+ |B| −�

�{3}�

�= 3+ 2− 1= 4.

The Subtraction Rule for two arbitrary sets A and B:

|A∪ B|= |A|+ |B| − |A∩ B|

Page 40: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 40

The Subtraction Rule

A= {1, 2, 3}

B = {3, 4}

A∪ B = {1, 2, 3, 4}

Therefore, to get the correct value of |A∪B|, the number of commonelements must be subtracted:

|A∪ B|= |A|+ |B| −�

�{3}�

�= 3+ 2− 1= 4.

The Subtraction Rule for two arbitrary sets A and B:

|A∪ B|= |A|+ |B| − |A∩ B|

Page 41: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 41

Counting paths

This is a map with three cities, connected by roads.

Count the number of paths from city A to city C, such that eachcity is visited not more than once.

Page 42: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 42

Counting pathsThis is a map with three cities, connected by roads.

Count the number of paths from city A to city C, such that each cityis visited not more than once.

A→ C2+ 3 · 4= 14

Page 43: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 43

Counting pathsThis is a map with three cities, connected by roads.

Count the number of paths from city A to city C, such that each cityis visited not more than once.

A→ C or A→ B→ C:2+ 3 · 4= 14

Page 44: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 44

Counting round trips

This is a map with three cities, connected by roads.

Count the number of round trips starting in city B, such that citiesA and C are visited not more than once.

B→ A→ B 3 · 3= 9B→ C → B 4 · 4= 16

B→ A→ C → B 3 · 2 · 4= 24B→ C → A→ B 4 · 2 · 3= 24

Total 73

Page 45: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 45

Counting round trips

This is a map with three cities, connected by roads.

Count the number of round trips starting in city B, such that citiesA and C are visited not more than once.

B→ A→ B 3 · 3= 9B→ C → B 4 · 4= 16

B→ A→ C → B 3 · 2 · 4= 24B→ C → A→ B 4 · 2 · 3= 24

Total 73

Page 46: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 46

Counting round trips II

This is a map with three cities, connected by roads.

Count the number of round trips starting in city B, such that1) cities A and C are visited not more than once, and2) each road is used not more than once during a trip.

B→ A→ B 3 · 2= 6B→ C → B 4 · 3= 12

B→ A→ C → B 3 · 2 · 4= 24B→ C → A→ B 4 · 2 · 3= 24

Total 66

Page 47: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 47

Counting round trips II

This is a map with three cities, connected by roads.

Count the number of round trips starting in city B, such that1) cities A and C are visited not more than once, and2) each road is used not more than once during a trip.

B→ A→ B 3 · 2= 6B→ C → B 4 · 3= 12

B→ A→ C → B 3 · 2 · 4= 24B→ C → A→ B 4 · 2 · 3= 24

Total 66

Page 48: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 48

Tree DiagramsCounting problems can be solved using tree diagrams.

Each branch represent one possible choice.Each possible outcome is a leaf of the tree (an endpoint that doesnot branch).

Example: Count all bit strings of length four.

16 strings.

Page 49: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 49

Tree DiagramsCounting problems can be solved using tree diagrams.

Each branch represent one possible choice.Each possible outcome is a leaf of the tree (an endpoint that doesnot branch).

Example 2: Count all bit strings of length four that do not have twoconsecutive 1s.

8 strings.

Page 50: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 50

Ranking cats

Page 51: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 51

Ranking cats

In how many different ways can you ranka set of 6 cats:

{a, b, c, d, e, f }

There are 6 ways to select the first cat,

5 ways to select the second cat among the remaining five,

4 ways to select the third cat . . .

. . . continue the process

In the end, the only remaining cat takes the last position in the rank.

6 · 5 · 4 · 3 · 2 · 1ways

Page 52: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 52

Ranking catsIn how many different ways can you ranka set of 6 cats:

{a, b, c, d, e, f }

• There are 6 ways to select the first cat,

• 5 ways to select the second cat among the remaining five,

• 4 ways to select the third cat . . .

• . . . continue the process

• In the end, the only remaining cat takes the last position inthe rank.

6 · 5 · 4 · 3 · 2 · 1ways.

Page 53: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 53

Ranking catsIn how many different ways can you ranka set of 6 cats:

{a, b, c, d, e, f }

• There are 6 ways to select the first cat,

• 5 ways to select the second cat among the remaining five,

• 4 ways to select the third cat . . .

• . . . continue the process

• In the end, the only remaining cat takes the last position inthe rank.

6 · 5 · 4 · 3 · 2 · 1 ways!

Page 54: Counting - GitHub Pages · TheRuleofProduct TheRuleofSum FiniteSets Overcounting SubtractionRule Counting TreeDiagrams Factorial p.5 Problem The chairs of an auditorium are to be

The Rule of ProductThe Rule of SumFinite SetsOvercountingSubtraction RuleCountingTree DiagramsFactorial

p. 54

FactorialHow large this number is?

6 · 5 · 4 · 3 · 2 · 1= 720

This function is called factorial and denoted by n!:

1!= 1

2!= 2 · 13!= 3 · 2 · 14!= 4 · 3 · 2 · 15!= 5 · 4 · 3 · 2 · 16!= 6 · 5 · 4 · 3 · 2 · 1n!= n · (n− 1) · (n− 2) · (n− 3) · . . . · 1

and by convention,

0!= 1