ICS141: Discrete Mathematics for Computer Science I

Similar documents
Pigeonhole Principle Solutions

Basics of Counting. The product rule. Product rule example. 22C:19, Chapter 6 Hantao Zhang. Sample question. Total is 18 * 325 = 5850

(Refer Slide Time: 01.26)

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Chapter 4. IP Addresses: Classful Addressing

Automata and Formal Languages

6.2 Permutations continued

MACM 101 Discrete Mathematics I

Solutions for Practice problems on proofs

1(a). How many ways are there to rearrange the letters in the word COMPUTER?

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

14.1 Rent-or-buy problem

Lecture 17 : Equivalence and Order Relations DRAFT

8 Divisibility and prime numbers

Computing exponents modulo a number: Repeated squaring

Math 55: Discrete Mathematics

Worksheet for Teaching Module Probability (Lesson 1)

WOLLONGONG COLLEGE AUSTRALIA. Diploma in Information Technology

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 10

5.2 Percent: Converting Between Fractions, Decimals, and Percents

Ch5: Discrete Probability Distributions Section 5-1: Probability Distribution

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Discrete Mathematics Problems

Math 55: Discrete Mathematics

1. The Fly In The Ointment

Reading 13 : Finite State Automata and Regular Expressions

COMBINATORIAL PROPERTIES OF THE HIGMAN-SIMS GRAPH. 1. Introduction

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

Chapter What is the probability that a card chosen from an ordinary deck of 52 cards is an ace? Ans: 4/52.

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Basic Probability Concepts

JUST-IN-TIME SCHEDULING WITH PERIODIC TIME SLOTS. Received December May 12, 2003; revised February 5, 2004

Full and Complete Binary Trees

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Computational Models Lecture 8, Spring 2009

8.3 Probability Applications of Counting Principles

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Minimax Strategies. Minimax Strategies. Zero Sum Games. Why Zero Sum Games? An Example. An Example

k, then n = p2α 1 1 pα k

3. Mathematical Induction

Probability: Terminology and Examples Class 2, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

Circuits and Boolean Expressions

Chapter 4 IP Addresses: Classful Addressing

The Chinese Remainder Theorem

8 Primes and Modular Arithmetic

s = s = s =

About the inverse football pool problem for 9 games 1

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

Regular Languages and Finite Automata

Math Circle Beginners Group October 18, 2015

Math Workshop October 2010 Fractions and Repeating Decimals

2 When is a 2-Digit Number the Sum of the Squares of its Digits?

Prime Time: Homework Examples from ACE

Working with whole numbers

Grade 7/8 Math Circles Fall 2012 Factors and Primes

Mathematical Induction. Lecture 10-11

Math 319 Problem Set #3 Solution 21 February 2002

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Colored Hats and Logic Puzzles

Cryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur

Thinking of a (block) cipher as a permutation (depending on the key) on strings of a certain size, we would not want such a permutation to have many

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Graphs without proper subgraphs of minimum degree 3 and short cycles

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

NP-Completeness and Cook s Theorem

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur


Quotient Rings and Field Extensions

If A is divided by B the result is 2/3. If B is divided by C the result is 4/7. What is the result if A is divided by C?

Algebra 1: Basic Skills Packet Page 1 Name: Integers ( 30) ( 4)

You know from calculus that functions play a fundamental role in mathematics.

Lecture 3: Finding integer solutions to systems of linear equations

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

Number Theory. Proof. Suppose otherwise. Then there would be a finite number n of primes, which we may

1. Prove that the empty set is a subset of every set.

Clock Arithmetic and Modular Systems Clock Arithmetic The introduction to Chapter 4 described a mathematical system

Discrete Math in Computer Science Homework 7 Solutions (Max Points: 80)

Zero-knowledge games. Christmas Lectures 2008

Ready, Set, Go! Math Games for Serious Minds

Combinatorial Proofs

Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

Chapter 11 Number Theory

Probability. Section 9. Probability. Probability of A = Number of outcomes for which A happens Total number of outcomes (sample space)

Mathematical Induction

Automata and Computability. Solutions to Exercises

Answer: The relationship cannot be determined.

The positive minimum degree game on sparse graphs

Discrete mathematics

Sample Induction Proofs

Just the Factors, Ma am

INCIDENCE-BETWEENNESS GEOMETRY

1. The RSA algorithm In this chapter, we ll learn how the RSA algorithm works.

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Sudoku puzzles and how to solve them

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

7 th Grade Integer Arithmetic 7-Day Unit Plan by Brian M. Fischer Lackawanna Middle/High School

COUNTING SUBSETS OF A SET: COMBINATIONS

Lecture Note 1 Set and Probability Theory. MIT Spring 2006 Herman Bennett

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

So let us begin our quest to find the holy grail of real analysis.

Transcription:

ICS141: Discrete Mathematics for Computer Science I Dept. Information & Computer Sci., Jan Stelovsky based on slides by Dr. Baek and Dr. Still Originals by Dr. M. P. Frank and Dr. J.L. Gross Provided by McGraw-Hill 13-1

Lecture 24 Chapter 5. Counting 5.1 The Basics of Counting 5.2 The Pigeonhole Principle 5.3 Permutations and Combinations 13-2

Review Sum Rule: If a task can be done in one of n 1 ways, or in one of n 2 ways,, or in one of n m ways, where none of the set of n i ways of doing the task is the same as any of the set of n j ways, for all pairs i and j with 1 i < j m. Then the number of ways to do the task is n 1 + n 2 + + n m. Product Rule: Suppose that a procedure can be broken down into a sequence of m successive tasks. If the task T 1 can be done in n 1 ways; the task T 2 can then be done in n 2 ways;...; and the task T m can be done in n m ways, then there are n 1 n 2 n m ways to do the procedure. 13-3

The Product Rule: Example Show that a set {x 1,, x n } containing n elements has 2 n subsets. A subset can be constructed in n successive steps: Pick or do not pick x 1, pick or do not pick x 2,, pick or do not pick x n. Each step can be done in two ways. Thus the number of possible subsets is 2 2 2 = 2 n. n factors 13-4

The Product Rule: Example What is the value of k after the following code has been executed? k := 0 for i 1 := 1 to n 1 for i 2 := 1 to n 2 n 1 n 2 n m for i m := 1 to n m k := k + 1 13-5

The Product Rule: Example How many functions are there from a set with m elements to one with n elements? n m How many one-to-one functions are there from a set with m elements to one with n elements? n (n 1)(n 2) (n m + 1) More examples in the textbook 13-6

IP Address Example In version 4 of the Internet Protocol (IPv4) Internet address is a string of 32 bits Network number (netid) + host number (hostid) Valid computer addresses are in one of 3 types: A class A IP address consists of 0, followed by a 7-bit netid 1 7, and a 24-bit hostid A class B address has 10, followed by a 14-bit netid and a 16-bit hostid. A class C address has 110, followed by a 21- bit netid and an 8-bit hostid. The 3 classes have distinct headers (0, 10, 110) Hostids that are all 0s or all 1s are not allowed. e.g., hawaii.edu is 128.171.224.100 13-7

IP Address Example How many valid computer addresses are there? 13-8

IP Address Solution # of addresses = (# class A) + (# class B) + (# class C) (by sum rule) # class A = (# valid netids) (# valid hostids) (by product rule) # valid class A netids = 2 7 1 = 127. # valid class A hostids = 2 24 2 = 16,777,214. Continuing in this fashion we find the answer is: 3,737,091,842 (3.7 billion IP addresses) 13-9

Set Theoretic Version If A is the set of ways to do task 1, and B the set of ways to do task 2, and if A and B are disjoint, then: The ways to do either task 1 or 2 are A B, and A B = A + B The ways to do both task 1 and 2 can be represented as A B, and A B = A B 13-10

Inclusion-Exclusion Principle Suppose that k out of m ways of doing task 1 also simultaneously accomplish task 2. And there are also n ways of doing task 2. Then, the number of ways to accomplish Do either task 1 or task 2 is m + n - k. Set theory: If A and B are not disjoint, then A B = A + B - A B. If they are disjoint, this simplifies to A + B. 13-11

Inclusion-Exclusion Example Some hypothetical rules for passwords: Passwords must be 2 characters long Each character must be a letter a ~ z, a digit 0 ~ 9, or one of the 10 punctuation characters! @ # $ % ^ & * ( ) Each password must contain at least one digit or punctuation character 13-12

Setup of Problem A legal password has a digit or punctuation character in position 1 or position 2. These cases overlap, so the principle applies. # of passwords with OK symbol in position #1 = (10 + 10) (10 + 10 + 26) = 20 46 = 920 # with OK symbol in pos. #2 = 46 20 = 920 # with OK symbol both places = 20 20 = 400 Answer: 920 + 920 400 = 1,440 13-13

Tree Diagrams A tree diagram can be used in many different counting problems. To use trees in counting, we use a branch to represent each possible choice. We represent the possible outcomes by the leaves, which are the endpoints of branches not having other branches starting at them. 13-14

Tree Diagrams: Example How many bit strings of length four do not have two consecutive 1s? 13-15

Tree Diagrams: Example A playoff between two teams consists of at most five games. The first team that wins three games wins the playoff. In how many different ways can the playoff occur? 13-16

The Pigeonhole Principle A.k.a. the Dirichlet drawer principle or the Shoe Box Principle. If k + 1 or more objects are assigned to k places, then at least 1 place must be assigned 2 or more objects. In terms of the assignment function: If f: A B and A B + 1, then some element of B has more than two preimages under f. I.e., f is not one-to-one. 13-17

The Pigeonhole Principle Proof by contradiction: If the conclusion is false, each pigeonhole contains at most one pigeon and in this time, we can account for at most k pigeons. Since there are k + 1 pigeons, we have a contradiction. 13-18

Pigeonhole Principle: Example There are 101 possible numeric grades (0% ~ 100%) rounded to the nearest integer. Also, there are >101 students in a class. Therefore, there must be at least one (rounded) grade that will be shared by at least 2 students at the end of the semester. i.e., the function from students to rounded grades is not a one-to-one function. 13-19

Another Example of P.P. 10 persons have first names as Alice, Bernare, and Charles, and last names as Lee, McDuff, and Ng. Show that at least two persons have the same first and last names. Solution: 9 possible names for the 10 persons 10 pigeons and 9 pigeonholes. Assignment of names to people = assignment of pigeonholes to the pigeons By the Pigeonhole Principle, some name (pigeonhole) is assigned to at least two persons (pigeons). 13-20

Generalized Pigeonhole Principle If N objects are assigned to k places, then at least one place must be assigned at least N/k objects. E.g., there are N = 280 students in a class. There are k = 52 weeks in the year. Therefore, there must be at least 1 week during which at least 280/52 = 5.38 = 6 students in the class have a birthday. 13-21

Proof of G.P.P. By contradiction. Suppose every place has < N/k objects, thus N/k 1. Then the total number of objects is at most N N N k k = k = k < + 1 1 1 k k N So, there are less than N objects, which contradicts our assumption of N objects! 13-22

G.P.P. Example I Given: There are 280 students in a class. Without knowing anybody s birthday, what is the largest value of n for which we can prove using the G.P.P. that at least n students must have been born in the same month? Answer: 280/12 = 23.3 = 24 13-23

G.P.P. Example II What is the least number of area codes needed to guarantee that the 25 million phones in a state can be assigned distinct 10-digit telephone numbers? Phone #: NXX-NXX-XXXX Solution N: 2 ~ 9 and X: any digit NXX-XXXX: (8 10 10) (10 10 10 10) = 8 million By G.P.P. at least 25,000,000/8,000,000 = 4 phones have the identical numbers Hence, at least 4 area codes are required 13-24

Fun Pigeonhole Proof Example 4: n N, a multiple m > 0 of n such that m has only 0 s and 1 s in its decimal expansion! Proof: Consider the n+1 decimal integers 1, 11, 111,, 1 1. They have only n possible remainders mod n. n+1 So, take the difference of two that have the same remainder. The result is the answer! 13-25

A Specific Case Let n=3. Consider 1, 11, 111, 1111. 1 mod 3 = 1 Note same residue 11 mod 3 = 2 111 mod 3 = 0 ç Lucky extra solution. 1,111 mod 3 = 1 1,111 1 = 1,110 = 3 370. It has only 0 s and 1 s in its expansion. Its remainder mod 3 = 0, so it s a multiple of 3. 13-26

Baseball Example Suppose that next June, the Marlins baseball team plays at least 1 game a day, but 45 games total. Show there must be some sequence of consecutive days in June during which they play exactly 14 games. Proof: Let a j be the number of games played on or before day j. Then, a 1,,a 30 Z + is a sequence of 30 distinct integers with 1 a j 45. Therefore a 1 +14,,a 30 +14 is a sequence of 30 distinct integers with 15 a j +14 59. Thus, (a 1,,a 30,a 1 +14,,a 30 +14) is a sequence of 60 integers from the set {1,..,59}. By the Pigeonhole Principle, two of them must be equal, but a i a j for i j. So, ij: a i = a j +14. Thus, 14 games were played on days a j +1,, a i. 13-27

Baseball Problem Illustrated Example of {a i }: Note all elements are distinct. 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 23, 25, 27, 29, 30, 31, 33, 34, 36, 37, 39, 40, 41, 43, 45 Then {a i +14} is the following sequence: 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30, 32, 33, 35, 36, 37, 39, 41, 43, 44, 45, 47, 48, 50, 51, 53, 54, 55, 57, 59 In any 60 integers from 1-59 there must be some duplicates, indeed we find the following ones: Thus, for example, exactly 14 games were played during days 3 to 11: 2+1+2+1+2+1+2 +1+2 16, 19, 21, 22, 25, 27, 30, 33, 36, 37, 39, 41, 43, 45 13-28