GGC

9. Counting

There are three basic counting rules used in this section, one for each of the arithmetic operations of multiplication, addition and subtraction.

9.1. The Product Rule ( and )

To find the total number of outcomes for two or more successive events where both events must occur, multiply the number of outcomes for each event together. For instance, if you want to find the number of outcomes possible when you roll a die and toss a coin, you could use the product rule. It is important to note that the events must be independent, meaning one doesn’t effect the other.

The Product Rule

If there are \(n\) ways event \(E\) can occur and \(m\) ways to event \(F\) can occur, where the occurance of \(E\) has no effect on \(F\), then there are \(nm\) ways \(E\) and \(F\) can occur.

This is called the product rule for counting because it involves multiplying to find a product. The product rule can be extended to more than two choices.

Think of the product rule when you see AND.
Example 1

A startup with four employee rents an office suite with seven offices. How many ways are there to assign the employees?

Solution

The first employee has 7 offices to choose from, the second has 6 offices to choose from, the third can choose from 5, and the fourth can choose from 4. By the product rule, there are \(7 \times 6 \times 5 \times 4 = 840\) ways to assign the offices.

Example 2 - Product Rule in Python

What will be the value 'counter' when the following code is run?

Example 3

Suppose there are 27 computers in a computer center and each computer has 15 ports. How many different ways are there to choose a specific port?

Solution

Choosing a port means you first choose a computer and then a port on that computer. Since there are 27 computers and 15 ways to choose a port on a computer, there are \(27 \times 15 = 405\) ways to choose a port.

You Try

How many functions are there from a set \(A\) with \(m\) elements to a set \(B\) with \(n\) elements?

Example 4 - Video using the product rule

9.2. The Sum Rule ( xor )

Consider finding the total number of ways a particular event occurs from a variety of different options. For instance, if you want to find the number of ways to pick an ITEC major to win a prize knowing there are students from many concentrations, you could use the sum rule. It is important to note the events must be mutually exclusive, meaning they do not have anything in common.

The Sum Rule

If there are \(n\) ways event \(E\) can occur and \(m\) ways event \(F\) can occur, and suppose that both events cannot occur at the same time, then there are \(n + m\) ways for \(E\) or \(F\) to occur.

This is called the sum rule for counting because it involves adding to find a total. The sum rule can also be extended to more than two choices.

Think of the sum rule when you see OR.
Example 5

A student in a Capstone course can choose a project from three different professors. The professors have 3, 7, and 4 possible projects, and no project is on more than one professor’s list. How many possible projects can the student choose?

Solution

The student can pick out a project by choosing from the first professor, the second professor, or the third professor. Since no project is on more than one list, the sum rules says that there are \(3 + 7 + 4 = 14\) projects to choose from.

You Try

If a card is drawn from a standard 52-card deck, how many ways can the card be an even number or a King?

Video Example

9.3. The Subtraction Rule ( or )

If your events are not mutually exclusive, to find the total number of possibilities use the subtraction rule.

The Subtraction Rule

Suppose event \(E\) can occur \(n\) ways, event \(F\) can occur \(m\) ways, and there are \(p\) ways that \(E\) and \(F\) both occur. Then there are \(n+m-p\) ways \(E\) or \(F\) can occur.

The subtraction rule is also called the inclusion-exclusion principle.

Example 6

A tech company recieves 200 applications for a position. 150 of the applicants were ITEC majors, 43 were business majors, and 25 were double majors in business and ITEC. How many application did not major in ITEC or business?

Solution

By the subtraction rule, there are \(150 + 43 - 25 = 168\) applicants that majored in ITEC or business. Thus \(200 - 168 = 32\) majored in neither of these.

Example 7

How many bit strings of length four start with 1 or end with 00?

Solution

A bit string of length four that starts with 1 will be of the form \(1~*~*~*\). For each \(*\) there are two choices, 0 or 1, so by the product rule, there are \(2^3\) bit strings of this form. A bit string of length four that ends with 00 will be of the form \(*~*~0~0\), so there are \(2^2\) bit strings of this form. Finally, a bit string of length four that starts with 1 and ends with 00 will be of the form \(1~*~0~0\), so there are 2 bit strings of this form. By the subtraction rule there are \(2^3 + 2^2 - 2 = 8+4-2=10\) possibilities.

You Try

If a card is drawn from a standard 52-card deck, how many ways can the card be black or a face card?

Video Example

9.4. The Pigeonhole Principle

A suprising number of counting problems can be solved with the so-called pigeonhole principle.

Pigeon Hole Principle

If \(n+1\) pigeons are resting in \(n\) pigeonholes then at least one pigeonhold contains more than one pigeon.

pigeons

Ten pigeons in nine pigeonholes

Example

In a group of 367 people at least two will have the same birthday because there are only 366 possible birthdays (counting February 29).

You Try

How many people, with English names, must be in a room for two of them to have a first name that starts with the same letter?

9.5. Permutations and Combinations

Consider the first four letters of the alphabet, \(A, B, C, D\). A permutation of these letters would be an arrangement of them in different orders.

  • \(ABCD, BACD, ABDC\) are permutations of the letters taken four at a time

  • \(BDA, ABC, ABD\) are permuations of the letters taken three at a time

  • \(AB, AC, DB\) are permutations of the letters taken two at a time

In general, given a set of \(n\) objects, an ordered arrangment of \(r \le n\) of them is called an \(r\)-permutation or a permutation of \(n\) objects taken \(r\) at a time . We will denote this by \(P(n,r)\). (Note that \(_nP_r\) is a commonly used notation, especially on calculators.)

Theorem

\(P(n,r) = n(n-1)(n-2) \cdots (n-r+1) = \displaystyle \frac{n!}{(n-r)!}\).

Example 8 - Permutations of 5 objects taken 3 at a time

Try to predict what happens with the code and verify.

You try

Try using Pythontutor to list permutations of 5 objects taken 4 at a time.

Example 9 - Counting Permutations

The code below calculates the number of permutations given \(n\) and \(r\). Try to predict the variable names, values, and data types at different steps in the execution. Use the Next button to check your answers.

You Try

Try using Pythontutor to count permutations using a factorial formula.

Video Example

Example 10

If there are 10 runners in a race, how many different ways can the gold, silver, and bronze medals be awarded?

Solution

There are 10 objects (the runners) and we are choosing 3 to win medals. So the number of ways they can be awarded is

\(P(10,3) = \displaystyle \frac{10!}{(10-3)!} = \frac{10!}{7!} = 10 \times 9 \times 8 = 720\)

Alternatively, we could have used the product rule and noticed that there are 10 ways to award the gold, then there are 9 ways to award the silver, then 8 ways to award the brozne.

Example 11

How many permutations of the digits 0123456789 are there that contain the string 456?

Solution

We can regard this as a permutation of 8 objects: the string 456 and the other 7 digits. Since they can occur in any order, the number of permutations is

\(P(8,8) = 8! = 40320.\)

You Try

From a group of 100 workers, how many ways can there be a union President, Vice President, and Treasurer?

You Try

How many different words (including nonsense words), can be formed using the letters in 'HEROIC' where the vowels must appear together?

Now consider the letters \(A, B, C, D\) and choose three at a time where the order does not matter. That is, the choice \(ABC\) is the same choice as \(BCA\). This selection where order does not matter is called a combination . There are only four possible ways to choose three letters without regard to order:

*\(ABC, ABD, ACD,\) and \(BCD\).

In general, given a set of \(n\) objects, and unordered selection of \(r\le n\) of them is an \(r\)-combination or a combination of \(n\) objects taken \(r\) at a time . We will denote this by \(C(n,r)\), read as '\(n\) choose \(r\)'. (Note that \(_nC_r\) is commonly used by calculators.)

Theorem

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

Example 12 - Combinations of 5 objects 3 at at time

The code below calculates the number of and lists combinations given \(n\) and \(r\). Try to predict the variable names, values, and data types at different steps in the execution. Use the Next button to check your answers.

You try

Try using Pythontutor to list and count combinations of 5 choose 4.

You try

Now try using Pythontutor to calculate combinations using factorials.

Video Example

Video Example

Example 13

How many ways can five cards be dealt from a standard 52-card deck?

Solution

We are choosing 5 cards from 52 cards and the order does not matter, so \(C(52,5)=\displaystyle \frac{52!}{5!47!}\)

Example 14

How many bit strings of length \(n\) contain exactly \(r\) 0s?

Solution

Choosing the positions of the \(r\) 0s corresponds to the \(r\)-combinations of the set \(\{1, 2, 3, \dots, n\}\). Thus there are exactly \(C(n,r)\) such bit strings.

9.6. Exercises

  1. There are 67 math majors and 124 ITEC majors at a college.

    1. In how many ways can two representatives be picked so that one is a math major and one is an ITEC major?

    2. In how many ways can one representative be picked who is either a math major or an ITEC major?

  2. A multiple-choice test contains 20 questions, and each question has four choices.

    1. In how many ways can a student answer all of the questions on the test?

    2. In how many ways can a student answer all of the questions if she is allowed to leave some blank?

  3. How many different three-letter initials can a person have?

  4. How many different three-letter initials end with "R"?

  5. How many bit strings are there of length five?

  6. How many bit strings are there of length five that begin and end with 1?

  7. How many bit strings are there of length less than \(n\), where \(n\) is a positive integer, that start and end with 1?

  8. How many license plates can be made using three digits followed by four uppercase English letters if:

    1. Digits and letters can be repeated?

    2. Digits and letters cannot be repeated?

  9. If each student in Discrete Mathematics is a mathematics major, an ITEC major, or a double major, and a class has 5 math majors (including double majors), 23 ITEC majors (including double majors), and 7 double majors, how many students are in the class?

  10. Suppose a computer system requires a password of length no less than 7 and no more than 10 characters, and each character must be an English lowercase letter, an English uppercase letter, a digit, or one of six special characters (*, >, <, !, +, =).

    1. How many different passwords are available?

    2. Suppose a hacker can check a potential password once every nanosecond (1 nanosecond is \(1 \times 10^{-9}\) seconds). How long will it take the hacker to check every potential password?

  11. Show that if there are 29 students in a class at least two have last names that begin with the same letter.

  12. How many students need to be in a class in order for at least two students to receive the same grade on an exam that is graded on a scale 0 to 100 points?

  13. Show that in any set of 5 integers, there are at least two of them that have the same remainder when divided by 4.

  14. A bag contains 8 red balls and 7 blue balls.

    1. How many balls must be chosen to be sure of choosing 3 of the same color?

    2. How many must be chosen to be sure of choosing 3 red balls?

  15. Someone cleaning out their attic finds a box containing 12 rock CDs and 12 country CDs. What is the minimum number of CDs they can take out to guarantee at least one of each type?

  16. Give an argument that there are at least two people in Atlanta with the same number of hairs on their head.

  17. There are 67 math majors and 124 ITEC majors at a college.

    1. In how many ways can two representatives be picked so that one is a math major and one is an ITEC major?

    2. In how many ways can one representative be picked who is either a math major or an ITEC major?

  18. A multiple-choice test contains 20 questions, and each question has four choices.

    1. In how many ways can a student answer all of the questions on the test?

    2. In how many ways can a student answer all of the questions if she is allowed to leave some blank?

  19. How many different three-letter initials can a person have?

  20. How many different three-letter initials end with "R"?

  21. How many bit strings are there of length five?

  22. How many bit strings are there of length seven that begin and end with 0?

  23. How many bit strings are there of length less than \(n\), where \(n\) is a positive integer, that start and end with 1?

  24. How many license plates can be made using four digits followed by three uppercase English letters if:

    1. Digits and letters can be repeated?

    2. Digits and letters cannot be repeated?

  25. If each student in Discrete Mathematics is a mathematics major, an ITEC major, or a double major, and a class has 18 math majors (including double majors), 25 ITEC majors (including double majors), and 8 double majors, how many students are in the class?

  26. Suppose a computer system requires a password of length no less than 8 and no more than 11 characters, and each character must be an English lowercase letter, an English uppercase letter, a digit, or one of six special characters (*, >, <, !, +, =).

    1. How many different passwords are available?

    2. Suppose a hacker can check a potential password once every nanosecond (1 nanosecond is \(1 \times 10^{-9}\) seconds). How long will it take the hacker to check every potential password?

  27. Show that if there are 29 students in a class at least two have last names that begin with the same letter.

  28. How many students need to be in a class in order for at least two students to receive the same grade on an exam that is graded on a scale 0 to 50 points?

  29. Show that in any set of 8 integers, there are at least two of them that have the same remainder when divided by 7.

  30. A bag contains 12 red balls and 7 blue balls.

    1. How many balls must be chosen to be sure of choosing 4 of the same color?

    2. How many must be chosen to be sure of choosing 4 red balls?

  31. Someone cleaning out their attic finds a box containing 12 rock CDs, 12 hip hop CDs, and 12 country CDs. What is the minimum number of CDs they can take out to guarantee at least one of each type?

  32. Give an argument that there are at least two people in Atlanta with the same number of hairs on their head.

  33. List all the permutations of \(\{1, 2, 3\}\).

  34. How many permutations are there of the set \(\{1, a, 2, b, 3, c, 5\}\)?

  35. Let \(A=\{a, b, c, d\}\)

    1. List all the 3-permutations of \(A\).

    2. List all the 3-combinations of \(A\).

  36. Let \(A=\{a, b, c, d, e\}\)

    1. List all the 2-permutations of \(A\).

    2. List all the 2-combinations of \(A\).

  37. Find the value of the following

    1. \(P(5,2)\)

    2. \(P(10,8)\)

    3. \(P(14,10)\)

    4. \(P(12,8)\)

    5. \(C(5,2)\)

    6. \(C(10,8)\)

    7. \(C(14,10)\)

    8. \(C(12,8)\)

  38. How many bit strings of length 10 contain:

    1. Exactly five 1s?

    2. At most five 1s?

    3. At least four 1s?

    4. The same number of 0s and 1s?

  39. How many permutations of the digits \(12345678\) contain:

    1. The string 284?

    2. The string 3581?

    3. The string 21 and 57?

  40. How many ways are there to choose 9 cards from a standard 52 card deck?

  41. How many ways can you be dealt a pair in a 5 card hand (2 cards of the same rank and 3 cards of a different rank)?

  42. How many ways can you be dealt a full house in a 5 card hand (2 cards of the same rank and 3 cards of the same rank)?

  43. How many license plates consist of 4 letters followed by 3 digits if:

    1. Repetition is allowed?

    2. Repetition is not allowed?

  44. Using \(C(n,r) = \displaystyle \frac{n!}{r!(n-r)!}\), evaluate the terms of this triangular table. Will you need the formula to extend the table to more rows?

\begin{array}{ccccccccccccc} &&&&&&&C(0,0)&&&&&&\\ &&&&&& C(1,0) && C(1,1) &&&&&\\ &&&&& C(2,0) && C(2,1) && C(2,2) &&&&\\ &&&& C(3,0) && C(3,1) && C(3,2) && C(3,3) &&&\\ &&& C(4,0) && C(4,1) && C(4,2) && C(4,3) && C(4,4) &&\\ \end{array}