Basics of Counting

https://slides.com/georgelee/ics141-basics-counting/live

Bigger Counting

Example Problems

  • The number of IPv4 addresses
  • How many poker hands are there?
  • How many 7 digit phone numbers are there?

Basic Counting Rules

Product Rule

Suppose a procedure can be broken down into a sequence of two tasks. If there are m ways to do task 1 and n ways to do task 2, then there are m*n ways to do the procedure.

Example - Poker Hands

Poker has a hand with 5 cards. How many total poker hands are there?

 

How many ways are there to make a royal flush? A straight flush?

The Sum Rule

Given a task, if the task can be done in either m ways or n ways, where neither of the ways overlap, then there are m + n ways to do the task.

Example - Grade

There are 5 letter grades and 3 status codes that may be put on your transcript for this class. How many possible values are there for this class on your transcript?

Overlap

When doing the sum rule, if there are tasks that overlap with each other, you must subtract it out to avoid double counting.

 

This is the Inclusion-Exclusion principle

Pigeonhole Principle

Example

If you have two colors of socks in a drawer, how many socks do you need to pull out to guarantee that you have two socks of the same color?

Pigeonhole Principle

"If I have 21 pigeons and 20 pigeonholes, then there must be at least one hole that has two pigeons".

 

Formally: If k is a positive integer and k + 1 or more objects are placed into k boxes, then there is at least one box containing two or more of the objects.

More Examples

  • How many students must be in a class to ensure that at least two get the same letter grade?
  • How many NFL football fans do you need in a room to make sure that there are two fans with the same team?

Generalized Version

If N objects are placed into k boxes, then there is one box with at least ⌈N/k⌉ objects.

 

Example: How many students must be in a class to ensure that 5 of them get the same letter grade?

 

There are five possible grades and we need a box with at least 5. So we have ⌈N/5⌉ = 5. The smallest integer is  

5 * 4 + 1 = 21.

Example

Chapter 6.2 Example 10:

During a month with 30 days, a baseball team plays at least one game a day, but no more than 45 games. Show that there must be a period of some number of consecutive days during which the team must play exactly 14 games.

Basics of Counting

By George Lee

Basics of Counting

  • 936