Math 55 - Spring 2004 - Lecture notes # 14 - March 9 (Tuesday) Read Chapter 4 Goals for Today: Continue counting principles Tree diagrams Pigeonhole principle Permutations Combinations Homework: 1) (Based on a recent 1st grade homework assignment from a local school.) 1.1) Suppose you can have 9 pieces of fruit, which can be either apples or oranges. How many ways can you have n pieces of fruit (for example, you could have 4 apples and 5 oranges, or 0 apples and 9 oranges, etc.) 1.2) Answer 1.1) for n pieces of fruit. 1.3) Suppose you can have 9 pieces of fruit, which can be apples, oranges or pears. How many ways can you have 9 pieces of fruit (actual 1st grade assignment). 1.4) Answer 1.3) for n pieces of fruit. 1.5) Suppose you can have n pieces of fruit, and there are m different kinds of fruit. How many ways can you have n pieces of fruit? 2) (Also based on a recent 1st grade homework assignment.) Suppose you can make shapes from putting together identical equilateral triangles edge-to-edge. Triangles must not overlap, and if they are adjacent, they must line up along an entire edge. In the picture below, the leftmost shape is ok, and the other two are not. Shapes must be connected (i.e. you can get from any triangle to any other triangle by moving across adjacent edges). (figure only in pdf and postscript versions of notes) How many different shapes using 2, 3, 4, 5, 6 and 7 triangles are there? Shapes are considered the same if one shape can be slid or rotated (but not turned over) to lie exactly on top of the other shape. (The 6 triangle problem was the actual 1st grade assignment. See if you can do 7.) 3) 4.1- 20, 42 4) 4.2- 10, 14 5) 4.3- 18, 24 6) 4.4- 10, 38 7) 4.5- 20, 54 Review Counting Principles 1) The Sum Rule: If S1 and S2 are disjoint sets, then the number of members of S1 U S2 is |S1 U S2| = |S1| + |S2| 2) Inclusion-Exclusion Principle: If S1 and S2 are arbitrary sets, then |S1 U S2| = |S1| + |S2| - |S1 inter S2| 3) The Product Rule: If S1 and S2 are sets, and S1 x S2 ={(s1,s2) : s1 in S1 and s2 in S2} is the Cartesian product of S1 and S2, then |S1 x S2| = |S1| x |S2| If S1, S2, ... , Sk are sets, S1 x S2 x ... Sk the Cartesian product, then |S1 x ... x Sk| = |S1| x ... x |Sk| 4) Tree diagrams EX: How many bit strings of length 4 without two consecutive zeros? Ans: 8; Enumerate all possibilities in a tree: Legal bit strings 0 - 1 0101 / / 0 0110 0 - 1 - 1 - 1 0111 / / 0 1010 / 0 - 1 - 1 1011 / / 0 - 1 1101 / / / / 0 1110 x -----1 - 1 - 1 - 1 1111 Bit # 1 2 3 4 Tree Diagrams (formally) Draw a tree where the children of each node represent all the possible values of the next entry EX: How many 2-out-of-3 game playoffs are there? Ans: 6 Winner sequence Winner b bb b / / b bab b b - a - a baa a / / b abb b / / b - a aba a x -- a - a aa a (5) Pigeonhole Principle: If k+1 or more objects (pigeons) are placed in k boxes (holes), then at least one box contains 2 or more objects. (proof by contradition: if each box had at most one object, there would only be k or fewer objects, a contradiction) EX: In any group of 27 English words, at 2 begin with the same letter, since there are only 26 letters. ASK&WAIT: How large a group of people do you need to be sure that two of them have the same first and last initials? ASK&WAIT: How many times do you have to shuffle a deck of cards, to be sure that the cards are in exactly the same order at least twice? (6) Generalized Pigeonhole Principle: If N or more objects (pigeons) are placed in k boxes (holes), then at least one box contains ceiling(N/k) or more objects. (proof by contradition: if each box had at most ceiling(N/K)-1 objects, there would be at most k*(ceiling(N/k) -1) < k*((N/k +1) - 1) = N objects, a contradiction) EX: N=k+1 implies ceiling(N/k)=ceiling((k+1)/k)=2, usual Pigeonhole principle ASK&WAIT: There are 200 students enrolled in Math 55. How many have to receive the same letter grade (A,B,C,D,F)? EX: Given any set S of n+1 positive integers less than or equal to 2*n, then one of them must divide another one: (ex: n=5, if S={2 3 5 7 9}, then 3|9) Proof: Let S = {a(1),a(2),...,a(n+1)}. Write a(i) = 2^(k(i)) * q(i), where q(i) is odd. So {q(1),...,q(n+1)} is a set of positive odd integers from 1 to 2n-1, of which there are only n, namely 1,3,5,...,2n-1. So by the pigeonhole principle, q(i)=q(j)=q for some i and j. Thus a(i) = 2^(k(i)) * q and a(j) = 2^(k(j)) * q. If k(i)>k(j) then a(j)|a(i), else a(i)|a(j). ASK&WAIT: Assuming California has 36M people, how many of them have the same 3 initials and were born on the same day of the same month (but not necessarily in the same year)? For example, Arnold B. Casey (ABC), born 29 Feb 1955 and Abigail B. Chen (ABC), born 29 Feb 1990 EX: Suppose you have n>1 computers, each of which chooses m other computers to which to establish a network connection. Computers can communicate in either direction over such a connection, and can forward messages from one computer to another. What is the smallest value of m such that there is a guaranteed path from any computer to any other computer, no matter where the connections go? Exs: n=2 (m=1), n=3 (m=1), n=4 (m=2) Solution: note that the answer <= n-1, since with n-1, every computer is directly connected to every other computer. We answer by asking what is the largest k such that each computer can be connected to k others, such that there is no path between some pair of computers, then m=k+1 Let N={all computers}. Suppose computer 1 can't reach 2. Let N1 be all the computers 1 can reach, and N2 be all ones it cannot reach (such as 2). Then N={all computers} = N1 U N2. The most number of edges you can have just connecting computers inside Ni is |Ni|-1, which gives a direct connection from every computer inside Ni to every other. Any more edges would connect some computer in Ni to some outside. Thus the max number of edges which can keep N1 and N2 unconnected is min(|N1|-1,|N2|-1) = min(|N1|,|N2|)-1. We want to pick |N1| to make this as large as possible, because this will tell us the largest number k of connections per computer we can have and not be completely connected. The largest min(|N1|,|N2|)-1 can be is k= min(floor(n/2),ceiling(n/2))-1 = floor(n/2)-1 and if we have m=k+1=floor(n/2) edges, we are guaranateed a connection. EX: Suppose you have a group of 6 people, where any 2 people are either friends or enemies. Show that either you have 3 mutual friends, or 3 mutual enemies, in the group. Proof: Take person A. Of the remaing 5 people, either at least 3 are friends of A, or at least 3 are enemies. Suppose first that at least 3 are friends of A. If any pair of these (say B and C) are friends, then A,B,C are 3 mutual friends and we are done. Otherwise, all 3 are mutual enemies and we are also done. If at least 3 of the 5 are enemies of A, the analogous proof works. 7) Permutations DEF: a permutation of a set S of n distinct objects is an ordered list of these objects DEF: an r-permutation is an ordered list of r elements of S EX: S={1,2,3}, all permutations={(1,2,3),(2,1,3),(1,3,2),(2,3,1),(3,1,2),(3,2,1)} all 2-permutations={(1,2),(2,1),(1,3),(3,1),(2,3),(3,2)} DEF: the number of r-permutations of a set S with n elements is P(n,r) Theorem: P(n,r) = n*(n-1)*(n-2)*...*(n-r+1) = n!/(n-r)! Proof: (product rule): there are n ways to choose the first in list, n-1 ways to choose second, ... , n-r+1 ways to choose rth EX: P(3,3)=3*2*1=6, P(3,2)=3*2=6 EX: how many different ways can a salesman visit 8 cities? P(8,8)=8!=40320 EX: How many different ways can 10 horses in a race win, place and show (come in first, second, third)? P(10,3) = 10*9*8 = 720 8) Combinations DEF: an r-combination from a set S is simply an unordered subset of r elements from S EX: S={1,2,3}, all 2-combinations={{1,2},{1,3},{2,3}} Comparing to all 2-permutations, we see we ignore order, DEF: C(n,r) = number of r-combinations from a set with n-elements Theorem: C(n,r) = n! / [ (n-r)! r! ] Proof: the set of all r-permutations can be formed from the set of all r-combinations by taking all r! orderings of each r-combination, so P(n,r)=r! * C(n,r), and C(n,r)=P(n,r)/r!= n! / [ (n-r)! r! ]= n*(n-1)*(n-2)*...*(n-r+1)/r! EX: C(3,2)=P(3,2)/2!=6/2=3 DEF C(n,r) also called binomial coefficient, written (n \\ r), pronounced "n choose r" Note that C(0,0)= 0!/0!*0! = 1; C(n,0)=C(n,n)=1 Corollary: C(n,r)=C(n,n-r) Proof: C(n,r)=n!/[(n-r)! r!] = n!/[ r! (n-r)!] = n!/[(n-(n-r))! (n-r)!] = C(n,n-r) EX C(3,1)=C(3,2)=1 DEF Pascal triangle: (0) (0) (1) (1) (0) (1) (2) (2) (2) (0) (1) (2) (3) (3) (3) (3) (0) (1) (2) (3) (4) (4) (4) (4) (4) (0) (1) (2) (3) (4) (5) (5) (5) (5) (5) (5) (0) (1) (2) (3) (4) (5) (6) (6) (6) (6) (6) (6) (6) (0) (1) (2) (3) (4) (5) (6) ... row sum 1 1 1 1 2 1 2 1 4 1 3 3 1 8 1 4 6 4 1 16 1 5 10 10 5 1 32 1 6 15 20 15 6 1 64 Note that to get any entry, you sum its neighbors to left above, right above Theorem: C(n,r)= C(n-1,r-1)+C(n-1,r) (Pascal's identity) Proof 1: need to show n! (n-1)! (n-1)! ----------- = ------------ + ------------ (n-r)!*r! (n-r)!*(r-1)! (n-r-1)!*r! multiply by (n-r)!*r!/(n-1)! to get n = 1 1 ----------- ------------ + ------------ 1 1/r 1/(n-r) or n = r + (n-r), which is true Proof 2: Let S be a set with n-1 elements, T=S U {x} , x not in S, be a set with n elements. then C(n,r) = |set of all r-subsets of T| = |set of all r-subsets of T containing x| + |set of all r-subsets of T not containing x| = |set of all r-1 subset of S| + |set of all r subsets of S| = C(n-1,r-1) + C(n-1,r) Theorem: sum_{r=0}^n C(n,r) = 2^n (note row sums of Pascals triangle) proof: 2^n = number of subsets of a set S with n elements = sum_{r=0}^n number of subsets of size r of S = sum_{r=0}^n C(n,r) Binomial Theorem: (x+y)^n = sum_{r=0}^n C(n,r) * x^r * y^{n-r} EX: (x+y)^0= 1 (x+y)^1= 1x + 1y (x+y)^2= 1x^2 + 2xy + 1y^2 (x+y)^3= 1x^3 + 3x^2y + 3xy^2 + 1y^2 (x+y)^4=1x^4 + 4x^3y + 6x^2y^2 + 4xy^3 + 1y^4 Proof 1: (x+y)^n=(x+y)*(x+y)*...*(x+y) n times what is coefficient of x^r*y^(n-r)? If we multiply out whole expression, get one x^r*y^(n-r) term for each subset of r terms (x+y) out of n from which we choose x, which is C(n,r) Proof 2: (induction) assume (x+y)^(n-1) = sum_{r=0}^(n-1) C(n-1,r) x^r y^(n-1-r) Then (x+y)^n=(x+y)*(x+y)^(n-1) =(x+y)*[ sum_{r=0}^(n-1) C(n-1,r) x^r y^(n-1-r) ] = sum_{r=0}^(n-1) C(n-1,r) x^(r+1) y^(n-1-r) + sum_{r=0}^(n-1) C(n-1,r) x^r y^(n-r) + (substitute s=r+1 in first sum) = sum_{s=1}^(n) C(n-1,s-1) x^s y^(n-s) + sum_{r=0}^(n-1) C(n-1,r) x^r y^(n-r) = sum_{s=1}^(n-1) C(n-1,s-1) x^s y^(n-s) + C(n-1,n-1) x^n + sum_{r=1}^(n-1) C(n-1,r) x^r y^(n-r) + C(n-1,0) y^n = x^n + y^n + sum_{r=1}^{n-1} (C(n-1,r-1)+C(n-1,r)) x^r y^(n-r) = x^n + y^n + sum_{r=1}^{n-1} (C(n,r)) x^r y^(n-r) by theorem: C(n,r)=C(n-1,r-1)+C(n-1,r) = sum_{r=0}^{n} (C(n,r)) x^r y^(n-r) as desired EX: what is coeff of x^12 y^13 in (2x-3y)^25 = sum_{r=0}^25 C(25,r) (2x)^r (-3y)^(n-r) = sum_{r=0}^25 C(25,r) 2^r (-3)^(n-r) x^r y^(n-r) = ... - C(25,12) 2^12 3^13 x^12 y^13 ... = ... - 25!/(12! 13!) 2^12 3^13 x^12 y^13 ... = ... - 3.4.. 10^16 x^12 y^13 ... ASK&WAIT: How many bit strings contain exact 5 zeros and 14 ones, if each zero is immediately followed by 2 ones? ASK&WAIT: show that C(2n,2)=2C(n,2)+n^2 ASK&WAIT: show that sum_{k=1}^n k*C(n,k) = n*2^(n-1):