Math 55 - Fall 2007 - Lecture notes # 21 - October 17 (Wednesday) Goals for today: Start Chapter 5 (counting) Counting principles: Sum, Product, Inclusion-exclusion, Tree diagrams, Pigeonhole principle Permutations Combinations Simple Motivating example for Chapter 5: Suppose you are in charge of making up the rules for acceptable passwords for customers of a new "dot com". What should the rules be to prevent a hacker from being able to try guessing passwords, i.e. trying a large number of random passwords in the hopes of getting lucky? In other words, how should you make the rules for legal passwords so that if a hacker tried this, testing one password every, say, 1 microsecond, it would probably take at least a month to find one? ASK&WAIT: suppose you permitted 1 upper case letter passwords? How long would it take to try them all? ASK&WAIT: suppose you permitted 2 upper case letter passwords? ASK&WAIT: suppose you permitted 6 upper case letter passwords? ASK&WAIT: suppose you permitted 8 letter passwords? ASK&WAIT: suppose you permitted 8 character passwords, with at least one nonletter? ASK&WAIT What is the chance of finding one in a month of trying random guesses? is this unlikely enough? Counting Principles 1) The Sum Rule: EX: If you have to do one project for a class, and are given one list with 2 projects and another with 3 different projects, how many different projects do you have to choose from? 2+3 = 5 The Sum Rule (formally): Suppose we have to choose one task to do, either T1 or T2. Let S1 be the set of n1 ways to do task 1, and S2 the set of n2 ways to do task 2, where S1 and S2 disjoint. The set of ways to do either T1 or T2 is S1 U S2. The number of ways to do either T1 or T2 is |S1 U S2| = |S1| + |S2| = n1 + n2 2) The Product Rule: EX: If you have to do two projects for a class, the first one chosen from a list of 2 projects, and the second one chosen from a list of 3 projects, how many different pairs of projects could you turn in? S1={p1,p2}, S2={pa,pb,pc} pairs={(p1,pa),(p1,pb),(p1,pc),(p2,pa),(p2,pb),(p2,pc)} = S1 x S2 2*3 = 6 different pairs The Product Rule (formally) Suppose we have two tasks to do, T1 and T2, with S1, n1, S2, n2 as above. The set of ways to do both T1 and T2 is S1 x S2. The number of ways to do both T1 and T2 is |S1 x S2| = |S1| * |S2| = n1 * n2 (remember S1 x S2 is the set of all pairs of entries {(x1,x2), xi in Si} 3) The Extended Product Rule: If S1 is the set of n1 ways to do T1, S2 the set of n2 ways to do T2, ... , Sm the set of nm ways to do Tm, then the set of ways to do T1,T2,...,Tm is S1xS2x...xSm, which has n1*n2*...*nm elements ASK&WAIT: How many bits strings of length 9 are there? ASK&WAIT: How many different license plates are there if all consist of three letters following by 3 numbers? ASK&WAIT: How many different computer passwords are there if they may be 8 characters, upper case letters only? ASK&WAIT: How many different computer passwords are there if they may be 6-8 characters long, upper or lower case letters, digits? ASK&WAIT: What if there must be at least one letter and one number? ASK&WAIT: How many functions f:X->Y are there, if X has m elements and Y has n? ASK&WAIT: How many one-to-one functions are there from X to Y? ASK&WAIT: How many ways can you shuffle a deck of 52 cards? EX: How many ways can a class of 100 students be divided in 2-student teams? 2 students {s1,s2} -> 1 way 4 students {s1,s2,s3,s4} -> 3 ways {(s1,s2),(s3,s4)}, {(s1,s3),(s2,s4)}, {(s1,s4),(s2,s3)} How do we get a simple formula for any even n? Suppose there are are P(n-2) pairings of n-2 students, whose names are 1, 2, ... , n-2; now add students n-1 and n What pairings are possible? Take student n, and choose any other student m to make the pair. That leaves n-2 students, with P(n-2) possible pairings. m can take on n-1 values, so there are (n-1)*P(n-2) possible pairings. Result: recurrence P(n) = (n-1)*P(n-2) , with P(2)=1 Are we sure we have counted every possibility exactly once? Use induction: assume P(n-2) is correct In construction, get (n-1) groups of P(n-2) pairings each, where n is paired with a different m in each group. So no pairing appears in more than one group. And no pairing can appear twice in one group because all P(n-2) groupings of n-2 students are different, by induction. And each pairing has to appear in one group, depending on partner of n. ASK&WAIT: What is a closed form formula for P(n)? For n=100: P(100) = 99*97*95*...*3 \approx 2.7e+78 n P_n 2 1 4 3 6 15 8 105 10 945 20 6.5e+08 40 3.2e+23 60 2.9e+40 100 2.7e+78 150 6.1e+130 350 2.3e+369 (number of atoms in universe once thought to be about 1e80) 4) Inclusion-Exclusion Principle: EX: How many 8-bit strings either start with 1 or end with 00? S1 = {1xxxxxxx, x= any bit}, S2 = {xxxxxx00, x=any bit} We want |S1 U S2|. But S1 and S2 overlap: S1 inter S2 = {1xxxxx00} So we count |S1| = 2^7, |S2| = 2^6. But |S1|+|S2|>|S1 U S2| because S1 inter S2 has been counted twice, so we subtract it: |S1 U S2| = |S1| + |S2| - |S1 inter S2| = 2^7 + 2^6 - 2^5 = 160 The Inclusion-Exclusion Principle (formally) Suppose we have two tasks to do, T1 and T2, with S1, n1, S2, n2 as above, except S1 and S2 may intersect. The set of ways to do both T1 and T2 is S1 U S2. The number of ways to do both S1 and S2 |S1 U S2| = |S1| + |S2| - |S1 inter S2| EX: How many <= 3 decimal digit numbers are divisible by 3 or by 4? Inclusion-Exclusion with 3 tasks (see Question 2.2.44) Suppose you have 3 tasks, in sets S1, S2, S3, which might overlap. Then | S1 U S2 U S3 | = |S1| + |S2| + |S3| - |S1 inter S2| - |S2 inter S3| - |S1 inter S3| + |S1 inter S2 inter S3 | EX: How many <= 3 decimal digit numbers are divisible by 3, 4 or 5? 5) 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 (6) 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 least 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? (7) 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 137 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. 8) 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 9) 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): EX: How many ways can a class of n students be divided into m person teams? We assume n = q*m, so there are q teams. We will first solve this problem in a straightforward way, getting a complicated answer as a product of combinatorial coefficients C(i,j) = i!/(j! (i-j)!) Then we will simplify this expression: most of the factorials will "miraculously" cancel after a great deal of algebra, leaving a very simple answer. This very simple answer will suggest a new, clever way to derive it in just a few lines. The point here is that many counting problems often have multiple ways to get the answer, and there is sometimes a clever short solution. Solution 1: This is straightforward, but leads to a complicated looking answers that we will have to simplify. Let T(n,m)= number of ways to divide n students into m person teams. Here is a recursive way to write down all possible m person teams: 1) Fix student #1 to be a member of team #1 2) From the remaining n-1 students, choose m-1 of them to also be members of team #1. There are C(n-1,m-1) ways to do this. 3) This leaves n-m students, to be divided into teams of m students. Applying the product rule to this recursive way of generating teams yields T(n,m) = (# ways to do steps 2) * (# ways to do step 3) = C(n-1,m-1)*T(n-m,m) This can be applied recursively, yielding T(n,m) = C(n-1,m-1)*T(n-m,m) = C(n-1,m-1)*C(n-m-1,m-1)*T(n-2*m,m) = C(n-1,m-1)*C(n-m-1,m-1)*C(n-2*m-1,m-1)*T(n-3*m,m) = ... = C(n-1,m-1)*C(n-m-1,m-1)*C(n-2*m-1,m-1)*C(n-3*m-1,m-1)*... *C(m-1,m-1) = prod_{i=0 to q-1} C(n-i*m-1,m-1) Substituting in the definition of C(j,k) yields a large number of factorials, but the numerator and denominator of adjacent terms turn out to cancel: Writing (n-1)! (n-m-1)! (n-2*m-1)! (m-(q-1)*m-1)! T(n,m) = ------------- * --------------- * --------------- * ... * -------------- (m-1)! (n-m)! (m-1)! (n-2*m)! (m-1)! (n-3*m)! (m-1)! 0! we we see that the (n-m)! in the 1st denominator and (n-m-1)! in the 2nd numerator mostly cancel the (n-2*m)! in the 2nd denominator and (n-2*m-1)! in the 3rd numerator mostly cancel the (n-3*m)! in the 3rd denominator and (n-3*m-1)! in the 4th numerator mostly cancel ... leaving (n-1)! 1 1 1 T(n,m) = ------------- * --------------- * --------------- * ... * -------- (m-1)! (n-m) (m-1)! (n-2*m) (m-1)! (n-3*m) (m-1)! 1 (n-1)! = -------------------------------------------- ((m-1)!)^q (n-m)(n-2*m)(n-3*m)...(n-(q-1)*m) (n-1)! = -------------------------------------------- ((m-1)!)^q (q*m-m)(q*m-2*m)(q*m-3*m)...(q*m-(q-1)*m) (n-1)! = ------------------------- ((m-1)!)^q (q-1)! m^(q-1) (n-1)! n = ------------------------- * --- ((m-1)!)^q (q-1)! m^(q-1) q*m n! = --------- (m!)^q q! which is a much simpler expression. So simple in fact that it calls out for a simpler way to get it, which we now describe. Solution 2: Let us start to write down all the ways of dividing all the students into q teams of m students each by writing down all n! ways of ordering n students, and just saying the first m students are the first team, the 2nd m students are the second team and so on. But it is clear that we have counted the same sets of teams too many times. Let us try to divide out n! by the number of multiple copies of the same set of teams. First, it is clear that no matter what the order of the first m students in the list is, we get the same team. Since there are m! such orders, we have counted sets of teams which differ only in the order of the first teams m! times too often, so we should divide by m!. Similarly, the order of the 2nd group of m students does not matter, so we should divide by m! again. The same argument applies to each of the q groups of m students, so we should divide by m! q times. But we are still not not done, because the team consisting of the first m students could appear anywhere in the q possible positions, as could the second group of m students, and so on. In other words, we have still counted the same set of teams q! times too often, because the teams can appear in q! possible orders, and still represent the same set of teams. So we have to divide by q! also. All in all, we get n!/( (m!)^q q!), which is the same answer we got before (whew!). EX: How many different desserts can you make out of 4 scoops of ice cream, each of which may be chocolate (C), vanilla (V) or strawberry (S)? Here are the 15 possibilities: CCCC VVVV SSSS CCCV VVVC SSSC CCCS VVVS SSSV CCVS VVCS SSCV CCVV VVSS CCSS Here is a more systematic way to get the answers: we will represent each dessert by a sequence of 4 stars (representing the 4 scoops) and 2 bars (dividing the starts into 3 groups: C, V and S). Here are some examples: **|*|* represents 2 Cs, 1 V and 1 S *|**|* represents 1 C , 2 V's and 1 S *|***| represents 1 C , 3 V's and 0 S's |****| represents 0 C , 4 V's and 0 S's ||**** represents 0 C , 0 V's and 4 S's etc The idea is that every sequence of 4 stars and 2 bars represents exactly one dessert. How many such sequences are there? The idea is that we take 6 possible possible positions (for 4 stars and 2 bars) and choose 2 of them for bars. There are C(6,2) = 6!/(2! 4!) = 15 ways to do this. Here is the general result: Theorem: Suppose I have n types of objects ("flavors"). How many differnt sets ("desserts") consisting of r objects ("scoops") are there? The answer is C(n+r-1,n-1). Proof: The idea is the same as before: each sequence of r stars ("scoops") and (n-1) bars represents a possible set. There are C(n+r-1,n-1) ways to pick n-1 places out of r+n-1 locations to put the bars. Ex: If I have n=3 flavors of ice cream, and make desserts of r=4 scoops, there are C(n+r-1,n-1)=C(3+4-1,3-1)=C(6,2)=15 different desserts. EX: How many anagrams are there of the word "mammal"? Recall that an anagram is a distint ordering of the letters. Here are some smaller examples: the word "the": The 6 anagrams are the, teh, eth, eht, het, hte the word "see": The 3 anagrams are see, ese, ees Here are different ways to try to solve this problem for the word "mammal", followed by the general result: Solution 1: Pick 3 locations for the m's Pick 2 of the remaining locations for the 2 a's Pick the remaining location for l By the product rule, the number of ways to pick locations is C(6,3) ... for the m's * C(3,2) ... for the a's * C(1,1) ... for the l = 20*3*1 = 60 Solution 2: Pick 1 location for the l Pick 3 of the remaining locations for the m's Pick the remaining 2 locations for the a's By the product rule, the number of ways to pick locations is C(6,1) ... for the l * C(5,3) ... for the m's * C(2,2) ... for the a's = 6*10*1 = 60, the same answer (whew!) Solution 3: Let us start by labeling the m's as m1,m2 and m3, and and the a's as a1 and a2, so we can distinguish them. So now we have 6 distinct symbols, m1,a1,m2,m3,a2,l, and the number of ways to order them is 6!. But clearly we have counted some ordering as distinct that we should not, so let's try to divide out by the number of multiple copies. For example, consider all the orderings where the first 3 characters are m's, and the last three are a1,a2,l. The are clearly 3! = 6 such orderings, since m1,m2,m3 can appear in the first three positions in any order, but yield the same anagram. This argument that we are counting each anagram 3! times works no matter where the 3 m's appear, so we should divide the number of orderings by 3! to account for the 3 m's. Similary, we should divide by 2! to account for the two a's. This yields 6!/ (3! 2!) = 60, the same answer (whew!) Solution 3 is the one that generalizes to arbitrary anagrams: Theorem: Suppose we have n(1) copies of symbol 1 n(2) copies of symbol 2 ... n(k) copies of symbol k Let n = n(1) + n(2) + ... + n(k). Then the number of distinct anagrams of these symbols is n! --------------------------- n(1)! n(2)! n(3)! ... n(k)! Proof 1: (hard way): We generate the anagrams as follows: Choose n(1) positions out of n for symbol 1 (there are C(n,n(1)) ways to do this) Choose n(2) positions of the remaining n-n(1) for symbol 2 (there are C(n-n(1),n(2)) ways to do this) Choose n(3) positions of the remaining n-n(1)-n(2) for symbol 3 (there are C(n-n(1)-n(2),n(3)) ways to do this) ... Choose n(k) positions of the remaining n-n(1)-n(2)-...-n(k-1) for symbol k (there is C(n-n(1)-n(2)-...-n(k-1),n(k)) = C(n(k),n(k))=1 way to do this) By the product rule we multiply these together to get C(n,n(1)) * C(n-n(1),n(2)) * C(n-n(1)-n(2),n(3)) * ... * C(n(k),n(k)) or n! (n-n(1))! (n-n(1)-n(2))! --------------- * -------------------- * ------------------------ * ... n(1)! (n-n(1))! n(2)! (n-n(1)-n(2))! n(3)! (n-n(1)-n(2)-n(3))! We can cancel the numerator in the i-th term with a factor of the denominators from the (i-1)-st term, leaving n! 1 1 ----- * ----- * ----- * ... n(1)! n(2)! n(3)! as desired. Proof 2 (easy way): Consider all n! permutations of the n symbols. Some of these are identical: Given a permutation, all n(1)! permutations with symbol 1 in the same positions are identical Given a permutation, all n(2)! permutations with symbol 2 in the same positions are identical ... Given a permutation, all n(k)! permutations with symbol k in the same positions are identical Therefore, we need to divide n! by n(1)!*n(2)!*...*n(k)! to get the correct number of anagrams.