Foundations of Computing – Discrete Mathematics Solutions to

advertisement
Foundations of Computing –
Discrete Mathematics
Solutions to exercises for week 12
Agata Murawska (agmu@itu.dk)
November 13, 2013
Exercise (6.1.2). A multiple-choice test contains 10 questions. There are
four possible answers for each question1 .
a) In how many ways can a student answer the questions on the test if the
student answers every question?
For each question a student has 4 options from which he chooses one.
That makes the number of ways to be equal to 410 by product rule.
b) In how many ways can a student answer the questions on the test if the
student can leave answers blank?
Now student has 5 options as he can choose any of the existing options
or leave no answer. Again by product rule, the number of ways is equal
to 510 .
Exercise (6.1.12). How many positive integers between 100 and 999 inclusive
a) are divisible by 7?
Every 7th number is divisible by 7, 1000 div 7 = 142. We have to
exclude numbers smaller than 100, there are 100 div 7 = 14 if them.
The final answer is therefore 142 − 14 = 128.
b) are odd?
Every 2nd number is odd. 1000 div 2 − 100 div 2 = 500 − 50 = 450
c) have the same three decimal digits?
It is simplest to just list these numbers: 111, 222, 333, 444, 555, 666, 777,
888 and 999 – there are 9 of them.
1
We are assuming there is exactly one correct answer to each question
1
d) are not divisible by 4?
There are 1000 div 4 − 100 div 4 = 250 − 25 = 225 numbers divisible
by 4 and 900 numbers between 100 and 999 in general, so there are 900 −
225 = 675 numbers not divisible by 4.
e) are divisible by 3 or 4?
There are 1000 div 4 − 100 div 4 = 225 numbers divisible by 4 and
1000 div 3 − 100 div 3 = 333 − 33 = 300 numbers divisible by 3. However, we have counted numbers divisible by 12 in both groups. There are
1000 div 12 − 100 div 12 = 83 − 8 = 75 numbers like that. Finally,
there are 225 + 300 − 75 = 450 numbers divisible by 3 or 4.
f) are not divisible by either 3 or 4?
We will use the solution from previous step. We know that 450 numbers
between 100 and 999 are divisible by 3 or by 4. Therefore, there are
900-450=450 numbers not divisible by either 3 or 4.
g) are divisible by 3 but not by 4?
There are 1000 div 3−100 div 3 = 333−33 = 300 numbers divisible by
3. Out of those, 1000 div 12−100 div 12 = 83−8 = 75 are also divisible
by 4 (as they are divisible by 3 ∗ 4 = 12. So there are 300 − 75 = 225
numbers divisible by 3 but not by 4.
h) are divisible by 3 and 4?
Numbers divisible by 3 and 4 are divisible by 12. There are 1000 div 12−
100 div 12 = 83 − 8 = 75 such numbers.
Exercise (6.2.4). The bowl contains 10 red balls and 10 blue balls. A woman
selects balls at random without looking at them.
a) How many balls must she select to be sure of having at least three balls
of the same color?
She must select 5 balls. A justification for this is the following: having
only 4 balls, you either have at least 3 of one color or you are in a situation
where you have 2 blue balls and 2 red ones. In the latter case, selecting
any additional ball gives you three balls of the same color. Therefore,
selecting 5 balls is sufficient.
Formally, we can use the generalized pigeonhole principle, where balls are
objects and colors are boxes. If we put 5 objects into 2 boxes, there is at
least one box (so, color of the balls) containing d 25 e = 3 objects.
b) How many balls must she select to be sure of having at least three blue
balls?
2
She must select 13 balls. To see this, consider the (unlikely) scenario that
first ten balls she selects are all red. Then she still needs to pick 3 more
balls to have three blue ones.
Exercise (6.3.8). A group contains n men and n women. How many ways
are there to arrange these people in a row if the men and women alternate?
We have to fill a row of length 2n in such a way that men and women alternate. Note that we can select order of men and order of women separately.
If W is the number of ways in which to order women and M is the number
of ways to order men, then the final answer will be 2 ∗ W ∗ M as the only
choice we have once men and women are “ordered” is whether to start the
final row with a man or a woman.
Now, it remains to calculate W and M . Notice, that in fact W = M as there
are n men and n women to arrange (and we have to “use” them all). In
how many ways can we arrange men? It will be a permutation of length n,
therefore by definition, M = P(n, n) = n(n − 1)(n − 2) . . . (n − n + 1) = n!.
Finally, the number of ways to arrange these people is 2 ∗ W ∗ M = 2 ∗ n! ∗ n!.
Exercise (6.3.12). A coin is flipped 10 times where each flip comes up either
heads or tails. How many possible outcomes
a) are there in total?
Each of 10 coins can come up heads (H) or tails (T ), There are 2 possible
outcomes when flipping one coin (H or T ), 4 possible outcomes when
flipping 2 coins (HH, HT , T H and T T ) and so on. In particular, for 10
coins there are 210 = 1024 possible outcomes.
b) contain exactly two heads?
If there are exactly two Hs, there are also exactly 8 T s when 10 coins
are flipped. This means that different possible outcomes come from the
exact order in which these two heads are obtained. We need to choose 2
positions out of 10 for the heads, so by definition of combination we have
10!
= 45 ways to get exactly 2 heads.2
C(10, 2) = 2!∗(10−2)!
c) contain at most three tails?
We will solve this by summing up number of possible outcomes with
exactly 0, 1, 2 and 3 tails. For 0 tails, there is only one possible outcome
– all heads. For 1 tails there are 10 possible outcomes, as the tails can
occur in any of the 10 flips. For 2 tails there are 45 possible outcomes (by
the same argument as we have used in part b) for exactly 2 heads). For
2
Notice, that if we want to instead choose 8 positions out of 10 for the tails, we get the
exact same result.
3
10!
3 tails there are C(10, 2) = 3!∗(10−3)!
= 120 possible outcomes. Finally,
summing it all up we get 1 + 10 + 45 + 120 = 176 possible outcomes with
three or less tails.
d) contain the same number of heads and tails?
There must be exactly 5 heads and 5 tails. Similarly to the case in part
b) we can only choose the 5 positions where the result will be heads.
10!
= 252 possible outcomes.
Therefore there are C(10, 5) = 5!∗(10−5)!
Exercise (6.3.16). Thirteen people on a softball team show up for a game.
a) How many ways are there to choose 10 players to take the field?
We choose 10 out of 13 players and we do not care about the order, in
which they are chosen. Therefore, we use definition of a combination.
13!
There are C(13, 10) = 10!∗3!
= 286 ways to choose 10 players.
b) How many ways there are to assign the 10 positions by selecting players
from the 13 people who show up?
We can solve this in two ways:
• We can use the previous solution and notice, that after the 10 players
were chosen, we can assign them positions in P(10, 10) = 10! ways,
resulting in 286 ∗ 10! = 1037836800 possibilities
• We can just choose 10 out of 13 people and assign them positions.
= 1037836800, so the exact same
This will result in P(13, 10) = 13!
3!
result.
c) Of the 13 people who show up, three are women. How many ways are
there to choose 10 players to take the field if at least one of these players
must be a woman?
Again, this part can be solved in two ways:
• There can be exactly 3, 2 or just 1 woman on the team. The choice
of men on the team is independent from the choice of women. For
3 women on the team, we choose men in C(10, 7) = 120 ways (as
there are 10 men and 7 slots for them) and there is only one way
3!
= 1).
to choose the women (which is consistent with C(3, 3) = 0!∗3!
For 2 women on the team, we choose men in C(10, 8) = 45 ways and
women in C(3, 2) = 3 ways, resulting in a total of 45∗3 = 135 options.
For 1 women on the team, we choose men in C(10, 9) = 10 ways and
woman in C(3, 1) = 3 way, resulting in a total of 10 ∗ 3 = 30 options.
Summing up these possibilities, there are 120 + 135 + 30 = 285 ways
to have at least one women on the team.
4
• From part a) we know that there were a total of 286 ways to have 10
people selected. In the current setting, with 10 men and 3 women
there is only one way to get a team with no women in it – it is to
take all the men. Therefore the remaining 285 ways must be ones
where at least one woman is on the team.
Exercise (6.5.4). How many ways are there to select five unordered elements
from a set with three elements when repetition is allowed?
We are asked to find a number of combinations where repetition is allowed.
The set contains n = 3 elements and we select r = 5 of them, therefore the
number of possible ways of doing that is C(n + r − 1, r) = C(7, 5) = 21.
Exercise (6.5.14). How many solutions are there to the inequality
x1 + x2 + x3 ≤ 11
where x1 , x2 and x3 are nonnegative integers?
Using the hint, we will introduce nonnegative integer x4 such that x1 + x2 +
x3 + x4 = 11.3 We need to find a way of selecting 11 items from a set of
four elements so that there are x1 items of type one, x2 items of type two,
x3 items of type three and x4 items of type four. This is again a number of
combinations where repetition is allowed: C(4 + 11 − 1, 11) = C(14, 11) =
14∗13∗12
= 308.
1∗2∗3
Exercise (6.5.26). How many different bit strings can be formed using six
1s and eight 0s?
We have 14 “boxes” to use up in total. We have to select places for objects
of one type (e.g. for 1s), then fill the rest of boxes with the 0s. This results
in the following number of different bit strings: C(14, 6) = 3003.
3
The reasoning follows the solution for example 5.
5
Download