0% found this document useful (0 votes)
29 views6 pages

ps9 Sol

This document contains the solutions to Problem Set 9 in Mathematics for Computer Science. It begins with solutions to two problems using the pigeonhole principle. It then solves a problem about counting passwords that avoid certain forbidden sequences. The remainder of the document involves counting problems related to cards, graphs, and numbers, providing combinatorial solutions using techniques like inclusion-exclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

ps9 Sol

This document contains the solutions to Problem Set 9 in Mathematics for Computer Science. It begins with solutions to two problems using the pigeonhole principle. It then solves a problem about counting passwords that avoid certain forbidden sequences. The remainder of the document involves counting problems related to cards, graphs, and numbers, providing combinatorial solutions using techniques like inclusion-exclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

6.042/18.

062J Mathematics for Computer Science November 2, 2010


Tom Leighton and Marten van Dijk

Problem Set 9 Solutions


Due: Monday, November 8

Problem 1. [10 points]

(a) [5 pts] Show that of any n + 1 distinct numbers chosen from the set {1, 2, . . . , 2n}, at
least 2 must be relatively prime. (Hint: gcd(k, k + 1) = 1.)
Solution. Treat the n + 1 numbers as the pigeons and the n disjoint subsets of the form
{2j − 1, 2j} as the pigeonholes. The pigeonhole principle implies that there must exist a
pair of consecutive integers among the n + 1 chosen which, as suggested in the hint, must
be relatively prime. 

(b) [5 pts] Show that any finite connected undirected graph with n ≥ 2 vertices must have
2 vertices with the same degree.
Solution. In a finite connected graph with n ≥ 2 vertices, the domain for the vertex
degrees is the set {1, 2, . . . , n − 1} since each vertex can be adjacent to at most all of the
remaining n−1 vertices and the existence of a degree 0 vertex would violate the assumption
that the graph be connected. Therefore, treating the n vertices as the pigeons and the n−1
possible degrees as the pigeonholes, the pigeonhole principle implies that there must exist
a pair of vertices with the same degree. 

Problem 2. [10 points] Under Siege!


Fearing retribution for the many long hours his students spent completing problem sets,
Prof. Leighton decides to convert his office into a reinforced bunker. His only remaining
task is to set the 10-digit numeric password on his door. Knowing the students are a clever
bunch, he is not going to pick any passwords containing the forbidden consecutive sequences
”18062”, ”6042” or ”35876” (his MIT extension).
How many 10-digit passwords can he pick that don’t contain forbidden sequences if each
number 0, 1, . . . , 9 can only be chosen once (i.e. without replacement)?
Solution. The number of passwords he can choose is the number of permutations of the
10 digits minus the number of passwords containing one or more of the forbidden words,
which we will find using inclusion-exclusion.
There are 6 positions 18062 could appear and the remaining digits could be any permutation
of the remaining 5 digits. Therefore, there are 6 · 5! passwords containing 18062. Similarly,
there are 7 · 6! passwords containing 6042 and 6 · 5! passwords containing 35876.
2 Problem Set 9

Each of the forbidden words contain the digit 6 and since he must choose each number
exactly once, the only way two forbidden words can appear in the same password is if they
overlap at 6. The only case where this can happen is if the password contains 35876042
and there are 3 · 2! such passwords.
By inclusion-exclusion the total number of passwords not containing any of the forbidden
words is
10! − (6 · 5! + 7 · 6! + 6 · 5!) + 3 · 2! = 3622326


Problem 3. [50 points] Be sure to show your work to receive full credit. In this problem
we assume a standard card deck of 52 cards.

(a) [4 pts] How many 5-card hands have a single pair and no 3-of-a-kind or 4-of-a-kind?

Solution. There is a bijection with sequence of the form:

(value of pair, suits of pair, value of other three cards, suits of other three cards)

Thus, the number of hands with a single pair is:


   
4 12
13 · · · 43 = 1, 098, 240
2 3

Alternatively, there is also a 3!-to-1 mapping to the tuple:

(value of pair, suits of pair,


value 3rd card, suit 3rd card, value 4th card, suit 4th card, value 5th card, suit 5th card)

Thus, the number of hands with a single pair is:

4

13 · 2
· 12 · 4 · 11 · 4 · 10 · 4
= 1, 098, 240
3!


(b) [4 pts] For fixed positive integers n and k, how many nonnegative integer solutions
x0 , x1 , . . . , xk are there to the following equation?
k
X
xi = n
i=0
Problem Set 9 3

Solution. There is a bijection from the solutions of the equation to the binary strings
containing n zeros and k ones where x0 is the number of 0s preceding the first 1, xk is the
number of 0s following the last 1 and xi is the number of 0s between the ith and (i + 1)th
1 for 0 < i < k.
 
n+k
k


(c) [4 pts] For fixed positive integers n and k, how many nonnegative integer solutions
x0 , x1 , . . . , xk are there to the following equation?
k
X
xi ≤ n
i=0

Solution. There is a bijection from the solutions of


k
X
xi ≤ n
i=0
= n − xk+1 (for some xk+1 ≥ 0)
and the solutions of
k+1
X
xi = n.
i=0
 
n+k+1
k+1


(d) [4 pts] How many simple undirected graphs are there with n vertices?
Solution. There are n2 potential edges, each of which may or may not appear in a given


graph. Therefore, the number of graphs is:


n
2( 2 )


(e) [4 pts] How many directed graphs are there with n vertices (self loops allowed)?
Solution. There are n2 potential edges, each of which may or may not appear in a given
graph. Therefore, the number of graphs is:
2
2n

4 Problem Set 9

(f ) [4 pts] How many tournament graphs are there with n vertices?


Solution. There are no self-loops in a tournament graph and for each of the n2 pairs of


distinct vertices a and b, either a → b or b → a but not both. Therefore, the number of
tournament graphs is:
n
2( 2 )


(g) [4 pts] How many acyclic tournament graphs are there with n vertices?
Solution. For any path from x to y in a tournament graph, an edge y → x would create
a cycle. Therefore in any acyclic tournament graph, the existence of a path between
distinct vertices x and y would require the edge x → y also be in the graph. That is, the
”beats” relation for such a graph would be transitive. Since each pair of distinct players are
comparable (either x → y or y → x) we can uniquely rank the players x1 < x2 < · · · < xn .
There are n! such rankings. 

(h) [4 pts] How many numbers are there that are in the range [1..700] which are divisible
by 2, 5 or 7?
Solution. Let S be the set of all numbers in range [1..700]. Let S2 be the numbers in this
range divisible by 2, S5 be the numbers in this range divisible by 5 and S7 be the numbers
in this range divisible by 7. By inclusion-exclusion, the number of elements in S divisible
by 2, 5 or 7 is
n = |S2 | + |S5 | + |S7 | − |S2 S5 | − |S2 S7 | − |S5 S7 | + |S2 S5 S7 |
700 700 700 700 700 700 700
= + + − − − +
2 5 7 2·5 2·7 5·7 2·5·7
= 350 + 140 + 100 − 70 − 50 − 20 + 10
= 460.


(i) [9 pts] In how many ways can you arrange n books on k bookshelf (assuming the order
of books on a shelf matters?)
Solution.  
n+k−1
n! ·
k−1


(j) [9 pts] How about if there has to be at least 1 book at each bookshelf?
Solution.    
n n−1
k! · · (n − k)! ·
k k−1

Problem Set 9 5

Problem 4. [15 points] Give a combinatorial proof of the following theorem:


n  
n−1
X n
n2 = k
k=1
k

(Hint: Consider the set of all length-n sequences of 0’s, 1’s and a single *.)
Solution. Let P = {0, . . . , n − 1} × {0, 1}n−1 . On the one hand, there is a bijection from
P to S by mapping (k, x) to the word obtained by inserting a * just after the kth bit in
the length-n − 1 binary word, x. So
|S| = |P | = n2n−1 (1)
by the Product Rule.
On the other hand, every sequence in S contains between 1 and n nonzero entries since the
∗, at least, is nonzero. The mapping from a sequence in S with exactly k nonzero entries
to a pair consisting of the set of positions of the nonzero entries and the position of the *
among these entries is a bijection, and the number of such pairs is nk k by the Generalized
Product Rule. Thus, by the Sum Rule:
n  
X n
|S| = k
k=1
k

Equating this expression and the expression (1) for |S| proves the theorem. 
Problem 5. [15 points] At a congressional hearing, there are 2n members present. Exactly
n of them are Democrats and n of them are Republicans. The members want to select a
smaller subcommittee of size n from within those present at the hearing. However, since the
Democrats currently hold majority, they want there to be more Democrats then Republicans
in the committee. In how many ways can you select such a committee? (Hint: Consider two
cases: n odd and n even.)
Solution. First, look at the case when n is odd. There are are
 
2n
n
ways to choose any subcommittee of size n. n is odd, so the number of Democrats is
always different than the number of Republicans in a committee. Each of these committees
will therefore either have more Democrats or more Republicans. However, there is an
equal number of Democrats and Republicans present at the hearing, so the number of
committees with more Republicans in them should by symmetry equal to the number of
committees with more Democrats in them. Consequently, the number of committees with
more Democrats than Republicans is
 
1 2n
.
2 n

6 Problem Set 9

If, however, n is even, then nn nn committees will have an equal number of Democrats
 
2 2
and Republicans (select n2 out of n Democrats and n2 out ofn Republicans). The number of
committees where one party has a majority is therefore 2n n
 n
n
− n n . Again by symmetry,
2 2
there must be     
1  2n n n
− n n
2 n 2 2
committees with more Democrats than Republicans.

You might also like