Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
MTAT.05.125: Introduction to Theoretical Computer Science University of Tartu Homework 1 Solution 1. Prove that n n . = n−k k Solution 1. Assume there are n balls with numbers 1, 2, . . . , n in a basket. Let us count how many ways there are to take k of these balls and put them into box. 1 2 3 4 5 6 7 basket: n − k balls box: k balls Figure 1: Taking k balls is the same as not taking n − k balls. On the one hand, we can choose k balls out of n and put them into the box – there are nk ways to do this. On the other hand, we can choose n − k balls out of n, i.e. those balls that n we want to leave in the basket (see Figure 1 for illustration); there are n−k ways to do this. Since the number in both solutions should be the same, we prove the formula. Solution 2. From the definition of binomial coefficient: n n n! n! n! = = = = . k n−k (n − k)! k! k! (n − k)! (n − (n − k))! (n − k)! 2. In the homework in Introduction to Theoretical Computer Science there was the following question: “how many binary vectors of length n with at least m zeros are there?” One student has answered “First, choose m places for zeros. in the remaining n − m places put Then, n n−m either zero or one. Therefore, the answer is m · 2 .” (a) Explain what was the mistake in the proposed solution. (b) What is the right answer? Solution. (a) The problem of the suggested solutions is that it overcounts the vectors, i.e. in general case vector is counted more than once. For instance, some particular vector with, say, m + 1 zeros will be counted m + 1 times as we can choose m of its m + 1 zeros in m + 1 different ways. See also Figure 2 for example. choose choose 1. locations for zeros 1. locations for zeros 0 0 0 0 0 0 put zeros in of put zeros in of rest 2. the locations rest 2. the locations 0 0 0 0 0 0 0 0 0 0 0 0 Figure 2: Example: n = 6 and m = 3. Two ways how we can count vector 000000 choosing 3 different locations for zeros. (b) There are ni binary vectors of length n with exactly i zeros. Now we just recall that “at least m zeros out of n” means “either m, or m + 1, . . . , or n zeros” and apply the addition principle: n X n . i i=m 3. How many 7-digit phone numbers are there ... (a) that do not contain digits ‘0’ and ‘7’ ? (b) that consist of digits ‘2’, ‘2’, ‘3’, ‘3’, ‘4’, ‘4’, ‘4’, end with digit ‘4’, and do not contain two consecutive digits ‘3’ ? Solution. (a) Every of 7 positions in a phone number can possess any of values ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘8’, ‘9’ – in total 8 choices for every position. This is exactly the definition of permutations with repetitions. Hence there are 87 = 2097152 such phone numbers. (b) First, since the last digit in the phone number is always ‘4’, we fix it and further we are interested in number of 6-digit phone numbers that consist of digits ‘2’, ‘2’, ‘3’, ‘3’, ‘4’, ‘4’: 2 2 3 3 4 4 If we forget for the moment about requirement on digits ‘3’, there are 6! 2!2!2! such 6-digit phone numbers (permutations of multiset {‘2’, ‘2’, ‘3’, ‘3’, ‘4’, ‘4’}). Now let us count complement, i.e. how many of these 6-digit phone numbers do contain two consecutive digits ‘3’. For that, we consider two consecutive digits ‘3’ as one object and we need to compose all the different permutations of the following “digits”: 2 2 33 2 4 4 There are 5! 2!1!2! such phone numbers (permutations of multiset {‘2’, ‘2’, ‘33’, ‘4’, ‘4’}). Altogether, the number of phone numbers we are asked to find in the problem, is a difference: 5! 6! − = 60 .x 2!2!2! 2!1!2! 4. There are n boys and n girls in the dance class. How many ways to arrange them in the pairs are there, such that each pair consists of a boy and a girl, and every dancer has a pair? Solution. Fix the boys in some order – for example, according to their height. Next we can arrange girls in line in front of boys in n! different ways (permutations) – this is exactly the number of ways to form different pairs. 1 2 3 4 5 5. A group of ten kids buys balloons in the shop. In the shop there are 20 red, 20 blue, 20 yellow and 20 green balloons. The balloons of the same color are identical. (a) How many possibilities for buying balloons are there if every kid buys exactly one balloon? (b) How many possibilities are there if every kid buys exactly two balloons of different colors? (c) How many possibilities are there if every kid buys one balloon and exactly 4 kids have bought a red balloon? (d) How many different combinations of balloons can be left in the shop if every kid buys exactly one balloon? Solution. Remark. The kids are human beings therefore they are all different! It means that for us it is important not only the total amount of balloons bought of each colour but also balloon of which colour each particular kid bought. (a) Since we have enough balloons of each colour even for the case when all the kids take balloons of the same colour, every kid is free to choose any of 4 colours independently of choices of other kids. We have a classical example of permutations with repetitions now, the answer is 410 = 1048576. (b) Again, since we have 20 balloons of each colour, we have more than enough balloons for every kid to be free to choose independently of other kids’ choices. For each kid there are 3 4 2 = 6 ways to choose two colours of his balloons. By multiplication principle the total number of kids’ choices is 610 = 60466176. (c) First we should choose those 4 lucky kids who get red balloons – there are 10 4 ways to do that. For each such selection, we have full freedom to assign to each other kid any of three colours left (blue, yellow or green). There are 36 ways to do that (permutations with repetitions). By multiplication principle, we get the final answer: 10 · 36 = 153090 . 4 (d) From the shop’s point of view, the combination of balloons left doesn’t depend on which kid bought balloon of which colour, only the total amount of balloons bought of each colour. If we assume, that in the shop balloons are usually kept in four boxes according to their colour, we need thus to count how many ways there are to choose 10 balloons from 4 boxes (while balloons from one box are considered identical). This is the same as to put 10 balloons into 4 empty boxes – exactly the definition of combinations with repetitions: 13 4 = 286 . = 10 10 4