/
The Basics of Counting:  Selected Exercises The Basics of Counting:  Selected Exercises

The Basics of Counting: Selected Exercises - PowerPoint Presentation

karlyn-bohler
karlyn-bohler . @karlyn-bohler
Follow
371 views
Uploaded On 2018-02-27

The Basics of Counting: Selected Exercises - PPT Presentation

Copyright Peter Cappello 2 Sum Rule Example There are 3 sizes of pink shirts amp 7 sizes of blue shirts How many types of shirts are there if a shirt type is a shirt of a particular color in a particular size ID: 638036

peter copyright rule cappello copyright peter cappello rule letters product exercise digit repeated amp divisible ways start continued bride

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "The Basics of Counting: Selected Exerci..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

The Basics of Counting: Selected ExercisesSlide2

Copyright © Peter Cappello

2

Sum Rule Example

There are

3

sizes of pink shirts & 7 sizes of blue shirts.How many types of shirts are there, if a shirt type is a shirt of a particular color in a particular size?

Pink

BlueSlide3

Copyright © Peter Cappello

3

Sum Rule

A

 B =  

|A  B| = |A| + |B|.ABSlide4

Copyright © Peter Cappello

4

Sum Rule Generalization

Let

{ S1, S

2, …, Sn } be a partition of S.Then, | S | = | S1 | + | S2 | + … + | Sn |.When using the sum rule, Check 1: Have I partitioned S?

Are the subsets pairwise disjoint?Is their union equal to S?Check 2: What equivalence relation

corresponds to my partition?Slide5

Copyright © Peter Cappello

5

Product Rule

Let

A

be a set of elements constructed in 2 stages.Stage 1 has n1

possible outcomes.For each outcome from Stage 1, Stage 2 has

n2 possible outcomes.Then,

| A |

=

n

1

n

2

.Slide6

Copyright © Peter Cappello

6

Product Rule Example

A store sells pink shirts & blue shirts;

each comes in small, medium, & large.How many types of shirts are there?

A shirt type can be described as an ordered pair: (color, size).Slide7

Copyright © Peter Cappello

7

Product Rule: Counting Ordered Pairs

Let

A be a set of objects that are constructed (described) in 2 stages.

Let S be the set of values from stage 1 Let T be the set of values from stage 2Then, | A | = | S | x | T |.An element of A can be described as an ordered pair (a, b)

, where a  S &

b  T.Slide8

Copyright © Peter Cappello

8

Product Rule Example

How many

sequences of 2 distinct

letters are there from { a, e, i, o, u } ?There are 5 ways to select the 1st letter in the sequence.There are 4 ways to select the 2nd letter in the sequence.The set of values in stage 2 depends on which letter was selected in stage 1.

The size of the set of values in stage 2 does not depend on which letter was chosen in stage 1.Slide9

Copyright © Peter Cappello9

9

Product Rule: Counting Ordered Pairs

The

product rule is a

special case of the sum rule: When{ S

1, S2, …, S

n } is a partition of A| Si

| = |

S

j

| = m,

for 1

i

, j

n

Thus,

|

S

1

| + | S

2

| + … + |

S

n

| = n| S

1

|.

The sum rule reduces to the product rule

:

Pick the subset (

n

);

Pick the element in the subset (

m

)Slide10

Copyright © Peter Cappello

10

Exercise 10

How many bit strings are there of length 8?Slide11

Copyright © Peter Cappello

11

Exercise 10

How many bit strings are there of length

8

?Use the product rule: Count the bit strings of length 8 by decomposing the process into 8 stages: count the possibilities for:the 1

st bit (2),

the 2nd bit (2),

…,

the 8

th

bit (

2

).

The product:

2

8

=

256

different bit strings.Slide12

Copyright © Peter Cappello

12

Exercise 20

How many positive integers < 1000

Are divisible by 7? Slide13

Copyright © Peter Cappello

13

Exercise 20

How many positive integers < 1000

Are divisible by 7?

└ 999/7 ┘ = 142.

Are divisible by 7 & 11

? (Use a Venn diagram)Slide14

Copyright © Peter Cappello

14

Exercise 20

How many positive integers < 1000

Are divisible by 7?

└ 999/7 ┘ = 142.

Are divisible by 7 & 11

?└ 999/(7

.

11)

= 12.

Are divisible by 7

but not by

11?

(Use a Venn diagram)Slide15

Copyright © Peter Cappello

15

Exercise 20

How many positive integers < 1000

Are divisible by 7?

└ 999/7 ┘ = 142.

Are divisible by 7 & 11

?└ 999/(7

.

11)

= 12.

Are divisible by 7

but not by

11?

Count the

# divisible

by 7;

Subtract

the

# divisible

by 7

&

11

;

999/7

-

999/(7

.

11)

= 142

12 = 130.Slide16

Copyright © Peter Cappello

16

Exercise 20 continued

4. Are divisible by 7

or 11?

(Use a Venn diagram)Slide17

Copyright © Peter Cappello

17

Exercise 20 continued

4. Are divisible by 7

or

11?We want property A or property B: use inclusion-exclusion:Count the

# that are divisible by 7;Add the

# that are divisible by 11;Subtract the

# that

are divisible by

both

;

999/7

+

999/11

999/(77)

= 142

+

90

12.

7

11Slide18

Copyright © Peter Cappello

18

Exercise 20 continued

5. Are divisible by

exactly one of 7 & 11?Slide19

Copyright © Peter Cappello

19

Exercise 20 continued

5. Are divisible by

exactly one

of 7 & 11?What region of the Venn diagram represents the answer?Count the symmetric difference: (union – intersection)

Count the # that are divisible by

7 or 11;└

999/7

+

999/11

999/(7

.

11)

= 142

+

90

12

=220.

Subtract

the # that

are divisible by

both

;

999/(7

.

11)

=

12

.

7

11Slide20

Copyright © Peter Cappello

20

Exercise 20 continued

6. Are divisible by neither 7 nor 11?

What region of the Venn diagram represents the answer?Slide21

Copyright © Peter Cappello

21

Exercise 20 continued

6. Are divisible by neither 7 nor 11?

What region of the Venn diagram represents the answer?

Count the universe (999).Subtract

the # that is divisible by 7 or 11 (

220) giving 779.

7

11Slide22

Generalize this heuristicGiven a universe U

and property,

P(e).Let S = { e | e in U, P(e) }What is |S|?Always ask the question “Is it easier to count S = U – S?If yes, then |S| = |U| - |S|.

Copyright © Peter Cappello22Slide23

Copyright © Peter Cappello

23

Exercise 20 continue

7. Have

distinct digits?

Omit leading 0s. For example 0 < 9 < 1000 and is composed of distinct digits. That is 9 is NOT distinct from 009.Slide24

Copyright © Peter Cappello

24

Exercise 20 continue

7. Have

distinct

digits?Use the sum rule to decompose the problem into counting The # of

1-digit numbers: 9The #

of 2-digit numbers with distinct digits:

Use the

product

rule:

Count the

# of

ways to select the

10s

digit:

9

Count the

# of

ways to select the

unit

digit:

9

There are

9

.

9 = 81

distinct 2-digit numbers.

The

# of

3-digit

numbers with distinct digits:

Use the

product

rule:

Count the

# of

ways to select the

100s

digit:

9

Count the

# of

ways to select the

10s

digit:

9

Count the

# of

ways to select the

unit

digit:

8

There are

9

.

9

.

8 = 648

distinct 3-digit numbers.

The overall answer is

9

+

81

+

648

=

738

.Slide25

Alternate approach Make a 3-level tree of 3-digit numbers

Top level (100s digit): branch: 0 vs. !0

Middle level (10s digit): branch: 0 vs. !0Bottom level (1s digit): branch: 0 vs. !0Add the solutions for the branches representing 3-digit numbers with distinct digits.

Copyright © Peter Cappello

25Slide26

000: Invalid – out of range

00X: 9

0X0: 9 x 1 = 90XY: 9 x 8 = 72X00: InvalidX0Y: 9 x 1 x 8 = 72XY0: 9 x 8 x 1 = 72XYZ: 9 x 8 x 7 = 504

Sum = 738

Copyright © Peter Cappello

26Slide27

Sara’s approachCount complement set; subtract from 999.

Sum rule:

Exactly 2 digits the same:2-digit numbers: 93-digit numbers:No “0”: XYY | YXY | YYX: 9 x 8 x 31 “0”: X0X | XX0: 9 x 22 “0”: X00: 9

Exactly 3 digits the same: XXX: 9Sum: 9 + 216 + 18 + 9 + 9 = 261; 999 – 261 = 738

Copyright © Peter Cappello

27Slide28

Copyright © Peter Cappello

28

Exercise 30

How many strings of

8 English letters

are there:If letters can be repeated? Slide29

Copyright © Peter Cappello

29

Exercise 30

How many strings of 8 English letters are there:

If letters can be

repeated? Use product rule: (26)8If no letter can be repeated?Slide30

Copyright © Peter Cappello

30

Exercise 30

How many strings of 8 English letters are there:

If letters can be repeated?

Use product rule: (26)8If no letter can be repeated?Use product rule: 26

. 25 . 24

. 23 . 22 .

21

.

20

.

19

c)

That start with

X

, if letters can be repeated?Slide31

Copyright © Peter Cappello

31

Exercise 30

How many strings of 8 English letters are there:

If letters can be repeated?

Use product rule: (26)8If no letter can be repeated?Use product rule: 26

. 25 . 24

. 23 . 22 .

21

.

20

.

19

c)

That start with

X

, if letters can be repeated?

Use product rule:

1

.

(26)

7

d) That start with

X

, if no letter can be repeated?Slide32

Copyright © Peter Cappello

32

Exercise 30

How many strings of 8 English letters are there:

If letters can be repeated?

Use product rule: (26)8If no letter can be repeated?Use product rule: 26

. 25 . 24

. 23 . 22 .

21

.

20

.

19

c)

That start with X, if letters can be repeated?

Use product rule:

1

.

(26)

7

d) That start with X, if no letter can be repeated?

Use product rule:

1

.

25

.

24

.

23

.

22

.

21

.

20

.

19

e) That start & end with

X

, if letters can be repeated?Slide33

Copyright © Peter Cappello

33

Exercise 30

How many strings of 8 English letters are there:

If letters can be repeated?

Use product rule: (26)8If no letter can be repeated?Use product rule: 26

. 25 . 24

. 23 . 22 .

21

.

20

.

19

c)

That start with X, if letters can be repeated?

Use product rule:

1

.

(26)

7

d) That start with X, if no letter can be repeated?

Use product rule:

1

.

25

.

24

.

23

.

22

.

21

.

20

.

19

e) That start & end with X, if letters can be repeated?

Use product rule:

1

.

1

.

(26)

6

Slide34

Copyright © Peter Cappello

34

Exercise 30 continued

f) That start with the letters

BO, if letters can be repeated?Slide35

Copyright © Peter Cappello

35

Exercise 30 continued

f) That start with the letters BO, if letters can be repeated?

Use product rule:

1 . 1 . (26)6

g) That start & end with the letters BO, if letters can be repeated?Slide36

Copyright © Peter Cappello

36

Exercise 30 continued

f) That start with the letters BO, if letters can be repeated?

Use product rule:

1 . 1 . (26)6

g) That start & end with the letters BO, if letters can be repeated?

Use product rule: 1 . 1 .

1

.

1

.

(26)

4

h) That start

or

end with the letters BO, if letters can be repeated?Slide37

Copyright © Peter Cappello 2011

37

h) That start

or

end with letters BO, if letters can be repeated?Use inclusion-exclusion:That start with the letters BO, if letters can be repeated:

(26)6That end with the letters BO, if letters can be repeated: (26)6Subtract those that start and end with the letters BO, if letters can be repeated: (26)4Overall answer: 2 . (26)

6 - (26)4

Exercise 30 continued

End

w/ BO

Start

w/ BOSlide38

Copyright © Peter Cappello

38

Exercise 40

How many ways can a wedding photographer

arrange 6

people in a row from a group of 10, where the bride & groom are among these 10, ifThe bride is in the picture?Slide39

Copyright © Peter Cappello

39

Exercise 40

How many ways can a wedding photographer

arrange

6 people in a row from a group of 10, where the bride & groom are among these 10, ifThe bride is in the picture?Use the

product rule:Pick the position

of the bride: 6Place the remaining 5

people from left to right in the remaining positions (use the

product

rule to do this):

9

.

8

.

7

.

6

.

5

Overall answer is

6

.

9

.

8

.

7

.

6

.

5

.Slide40

Copyright © Peter Cappello

40

Exercise 40 continued

b) Both the bride

& groom are in the picture?Slide41

Copyright © Peter Cappello

41

Exercise 40 continued

b) Both the bride

&

groom are in the picture?Use the product rule:Pick the bride’s position: 6Pick the

groom’s position: 5Place 4

people from the remaining 8 in the remaining 4

slots, from left to right:

8

.

7

.

6

.

5

.

The overall answer is

6

.

5

.

8

.

7

.

6

.

5.Slide42

Copyright © Peter Cappello

42

Exercise 40 continued

c) Exactly 1 of the bride & groom is in the picture?Slide43

Copyright © Peter Cappello

43

40 continued

c) Exactly 1 of the bride & groom is in the picture

? (symmetric difference of what?)

Pick either the bride or the groom: 2.Place that person in the picture:

6.Place remaining 5

from remaining 8 people: P(8, 5) =

8

.

7

.

6

.

5

.

4.

The overall

answer: 2

.

6

.

(

8

.

7

.

6

.

5

.

4)

=

80,640.

Slide44

Copyright © Peter Cappello

44

Exercise 50

A variable name in

C

can have uppercase & lowercase letters, digits, or underscores. The name’s 1st character is a letter (uppercase or lowercase), or an underscore. The name of a variable is determined by its 1st

8 characters. How many different variables can be named in C?Slide45

Copyright © Peter Cappello

45

Exercise 50

A variable name in C can have uppercase & lowercase letters, digits, or underscores.

The name’s 1st

character is a letter (uppercase or lowercase), or an underscore. The name of a variable is determined by its 1st 8 characters. How many different variables can be named in C?Use the sum rule to count the # of variable names of i characters, for i = 1, 2, …, 8. The overall answer is the sum of these numbers.Slide46

Copyright ©

Peter Cappello

46

Exercise 50 continued

Use the product rule to count the # of names of a fixed size.

Let the name have i characters.The # of ways to pick the 1st character is 2 . 26 + 1 = 53.The # of ways to pick subsequent characters is 53 + 10.The # of ways to pick the name is 53 . (63)i-1.The overall answer is

Σi=[1,8] 53 . (63)

i-1 ≈ 2.1 x 1014.Slide47

Copyright © Peter Cappello

47

EndSlide48

Copyright © Peter Cappello

48

Product Rule: Counting Ordered Pairs

Let

A

be a set of objects constructed (described) in 2 stages.Let S be the set of values from stage 1.If a

 S is selected in stage 1, let Ta be the set of values for stage 2.

Essentially, A = { (

a

,

b

) |

a

S

and

b

T

a

}.

To use the product rule, for all

a, b

S

, |

T

a

| = |

T

b

|.

(Illustrate

S

and

T

a

with previous examples)

The product rule is a

special case

of the sum rule:

When

{ S

1

, S

2

, …, S

n

} is a partition of A

| S

i

| = | S

j

|, for 1

i, j

n

The sum rule reduces to the product rule:

| S

1

| + | S

2

| + … + | S

n

| = n| S

1

|.

Slide49

Copyright © Peter Cappello

49

Characters

  

. ≥ ≡ ~ ┌

┐ └

┘       

  

 

Θ

    

Σ

       Slide50

Copyright © Peter Cappello

50

Exercise 20 continue

8. Have distinct digits

and are even?Slide51

Copyright © Peter Cappello

51

Exercise 20 continue

8. Have distinct digits

and

are even?Easier to: count the number that have distinct digits (738)

subtract those that are odd:

1-digit: 5

2-digit

:

40

5

ways to pick the

unit

digit

8

ways to pick the

10s

digit (nonzero)

3-digit

:

320

5

ways to pick the

unit

digit

8

ways to pick the

100s

digit (nonzero)

8

ways to pick the

10s

digit

The total that have distinct digits

&

are odd is

5

+

40

+

320

=

365.

The overall answer is

738

365

=

373.Slide52

Copyright © Peter Cappello

52

20 continued

The hard way: Use the sum rule directly:

1-digit

: 42-digit:

0 is not picked:

4

0 is picked:

1

low-order digit:

high-order digit:

9

8

9 + 32 = 41Slide53

Copyright © Peter Cappello

53

20 continued

3.

3-digit:

0 is not picked:

4

0 is picked:

1

low-order digit:

high-order digit:

9

8

72 + 256 = 328

8

8

middle digit:

The overall answer is

4 + 41 + 328 = 373

.Slide54

Copyright © Peter Cappello

54

40 continued

c) Exactly 1 of the bride & groom is in the picture?

There are 6

. 9 . 8 . 7 . 6 . 5 ways for the bride to be in the picture.There are 6 . 5

. 8 .

7 . 6 .

5.

ways for the bride

and

groom to be in the picture.

The number of ways

for the bride

only

to be in the picture

is

6

.

9

.

8

.

7

.

6

.

5

-

6

.

5

.

8

.

7

.

6

.

5 =

6

.

8

.

7

.

6

.

5 (9 – 5)

= 40,320.

There are

the same number of ways

for the

groom only

to be in the picture (a

1-to-1 correspondence

between bride-only & groom-only)

The overall answer is 2

.

40,320.

Slide55

Copyright ©

Peter Cappello

55

40 alternate answer for part c

c) Exactly 1 of the bride & groom is in the picture?

Use the product rule:Pick the bride or groom to be in the picture: 2.Count the number of ways to fill out that picture.

Use the product rule:Place the bride/groom: 6

Fill in the other positions from left to right: 8 . 7

.

6

.

5

.

4.

The overall answer is

2

.

6

.

8

.

7

.

6

.

5

.

4 = 80,640.