1 CSCI- 2200 FOUNDATIONS OF COMPUTER SCIENCE Spring 2015 April 2, 2015
2 Announcements Homework 6 is due next Monday, April 6 at 10am in class. Homework 6 ClarificaMon In Problem 2C, where you need to count the number of strings where G precedes A, G does not need to immediately precede A.
3 Review of CounMng I 1. How many strings of six uppercase English leters are there? 2. How many are there that start with a vowel? 3. How many are there that contain no vowels? 4. How many strings are there if leters cannot be repeated?
4 Review of CounMng I 1. How many strings of six uppercase English leters are there? 2. How many are there that start with a vowel? 3. How many are there that contain no vowels? 4. How many strings are there if leters cannot be repeated?
5 Review of CounMng II 1. How many funcmons are there from the set X = {0,1} to the set Y={1,2,3,4}. 2. How many of these funcmons are injecmve? 3. How many of these funcmons are surjecmve?
6 Review of CounMng III How many subsets of a set with 100 elements have more than 1 element?
7 Tree Diagrams Suppose that I Love FOCS T- shirts come in five different sizes: S,M,L,XL, and XXL. Each size comes in four colors (white, red, green, and black), except XL, which comes only in red, green, and black, and XXL, which comes only in green and black. What is the minimum number of shirts that the campus book store needs to stock to have one of each size and color available?
8 THE PIGEONHOLE PRINCIPLE SecMon 6.2
9 The Pigeonhole Principle Pigeonhole Principle: If k is a posimve integer and k + 1 objects are placed into k boxes, then at least one box contains two or more objects.
10 Proof of the Pigeonhole Principle Pigeonhole Principle: If k is a posimve integer and k + 1 objects are placed into k boxes, then at least one box contains two or more objects.
11 Example of the Pigeonhole Principle Among any group of 367 people, there must be at least two with the same birthday. How many possible birthdays are there? 366 What are the pigeonholes? The 366 birthdays What are the pigeons? The 367 people
Show that, among any group of five integers, there are two with the same remainder when divided by 4. 12
13 Show that for every posi?ve integer n there is a mul?ple of n that has only 0s and 1s in its decimal expansion (only contains the digits 0 and 1). Let n be a posimve integer. Consider the n + 1 integers 1, 11, 111,., 111 1 (where the last integer has n + 1 1s). There are n possible remainders when an integer is divided by n. By the pigeonhole principle, when each of the n + 1 integers is divided by n, at least two must have the same remainder. Let x be the largest one and let y be the smallest one. x y is divisible by n and contains only the digits 0 and 1.
14 The Generalized Pigeonhole Principle If N objects are placed into k boxes, then there is at least one box containing at least N/k objects. Among 100 people there are at least how many who were born in the same month?
Example - Generalized Pigeonhole Principle How many cards must be selected from a standard deck of 52 cards to guarantee that at least three cards of the same suit are chosen? 15
16 PERMUTATIONS AND COMBINATIONS SecMon 6.3
17 PermutaMons A permuta?on of a set of dismnct objects is an ordered arrangement of these objects. An ordered arrangement of r elements of a set is called an r- permuta?on. Example: Let S = {1,2,3}. 3,1,2 is a permutamon of S. 3,2 is a 2- permutamon of S. The number of r- permutamons of a set with n elements is denoted by P(n,r).
18 A Formula for the Number of PermutaMons Theorem: If n is a posimve integer and r is an integer with 1 r n, then there are P(n, r) = n(n 1)(n 2) (n r + 1) r- permutamons of a set with n dismnct elements. Proof: Use the product rule. The first element can be chosen in n ways. The second in n 1 ways, and so on until there are (n ( r 1)) ways to choose the last element. Note that P(n,0) = 1, since there is only one way to order zero elements.
19 CounMng PermutaMons How many ways are there to select a first- prize winner, a second prize winner, and a third- prize winner from 100 different people who have entered a contest?
20 More CounMng PermutaMons Suppose a saleswoman must visit 8 different cimes. She must begin her trip in a specified city, but she can visit the other seven cimes in any order she wishes. How many possible orders can the saleswoman use when visimng these cimes? SoluMon: The first city is chosen. Hence the number of possible orders is 7! = 7 6 5 4 3 2 1 = 5040 If she wants to Cind the tour with the shortest path that visits all the cities, she must consider 5040 paths!
21 The Traveling Salesman Problem Suppose a saleswoman must visit all 6 cimes. The distances between the cimes are given. What is the shortest tour she can take that visits every city exactly once and then returns to the starmng city?
22 Even More CounMng PermutaMons How many permutamons of the leters A, B, C, D,E, F,G, H contain the string ABC?
23 CombinaMons An r- combina?on of elements of a set is an unordered selecmon of r elements from the set. An r- combinamon is simply a subset of the set with r elements. The number of r- combinamons of a set with n dismnct elements is denoted by C(n, r). The notamon coefficient. is also used and is called a binomial
24 Example I - CombinaMons Let S be the set {a, b, c, d}. Then {a, c, d} is a 3- combinamon from S. It is the same as {d, c, a} since the order does not mater. What is C(4,2)? What is P(4,2)?
25 CombinaMons Theorem 2: The number of r- combinamons of a set with n elements, where n r 0, equals
How many poker hands of five cards can be dealt from a standard deck of 52 cards? 26
27 CombinaMons Corollary: Let n and r be nonnegamve integers with r n. Then C(n, r) = C(n, n r). Proof: From the previous theorem, it follows that and Hence, C(n, r) = C(n, n r).
A group of 30 people have been trained as astronauts to go on the first mission to Mars. How many ways are there to select a crew of six people to go on this mission? 28
How many bit strings of length 10 contain at least three 0s and at least three 1s? 29
30 Good Problems to Review SecMon 6.2: 3, 5, 7, 9, 17, SecMon 6.3: 3, 5, 7, 11, 15, 17, 19 21, 23, 27, 31, 33