Assignment 2 Solutions
Assignment 2 Solutions
Department of Mathematics
DMTH137 Discrete Mathematics I
S2 2019
Assignment 2
Due 07:00 am, Monday 28 October 2019
Notes for markers: (50 marks total) There are 25 marks available in each half of the unit: tested with
questions 1–4 for Functions, Counting Techniques; with another 25 for questions 5–8 covering Euclidean
algorithm, Congruences and Graph Algorithms.
sig 137
Be aware that work that is illegible, because of poor hand-writing say, or due to poor contrast within the
scan or photograph, will not be marked.
Where it is reasonable to work out large numbers exactly with a calculator, you should do so. Further-
t
more, solutions without at least a brief explanation or justification will receive no, or only partial, marks.
n
Functions, Counting Techniques
e
H
1. For each of the following rules, determine whether the function f : Z × Z → Z is onto.
nm
(a) f (m, n) = 2m − n Solution: (1 mark) To be onto, the range (the set of all images,
or outputs) is the same as the codomain (which in this example is Z.) If we set m = 0, we can
T
make 2m − n = −n any integer t by taking n = −t . This function is onto.
(b) f (m, n) = m2 − n2 Solution: (1 mark) Experiment a little. Can we find m and n so
that m2 − n2 is 0? Of course. What about 1? Of course. (Take m = 1 and n = 0.)
What about 2. No luck? Keep trying. Still no luck? Why not?
DM
First we only need concern ourselves with positive m and n since (−m)2 = m2 . We can write
m2 − n2 = (m + n)(m − n). If m and n differ by 2 or more, we can’t have (m + n)(m − n) = 2.
And if m and n are both more 1, then m + n is more than 2. Then try all the ways m and n are
less than 2. There is no way to make m2 − n2 = 2 .
2
Here is an alternative reason why we can’t find integer m and n so that m2 − n2 = 2. Rewrite
to obtain m2 = n2 + 2. That is, we seek squares which are precisely 2 apart. The squares are
0, 1, 4, 9, 16, . . . . It is evident that no two of these differ by precisely 2.
This function is not onto, since we have an element in the codomain which is not in the image.
As
1
f (0) = 0, f (1) = 4, f (2) = 2, f (3) = 0, f (4) = 4, and f (5) = 2.
The range is then {0, 2, 4}, which is not all of Z6 .
What if we take the same rule for f , namely x ↦→ 4 x, but use a different domain and codomain, namely
f : Z5 → Z5 with arithmetic being done modulo 5?
Solution: (2 marks) A direct approach is to first of all calculate all function values. We get the
following: f (0) = 0, f (1) = 4, f (2) = 3, f (3) = 2, f (4) = 1. Each image has been assigned
from 1, and only 1, input. So the function is 1–1.
The set of outputs is {0, 1, 2, 3, 4} = Z5 , so the function is onto.
3. (a) An online portal requires a user to login with a password, which must be from 6 to 8 characters
long where each character is an uppercase letter or a digit.
A password must contain at least 1 digit. How many possible passwords are there?
Solution: (3 marks) Say we have 6 characters, and N is the number of passwords, D is the
number of passwords with at least 1 digit, and Z is the number of passwords with zero digits. Then
N = D + Z, by the addition principle.
What is N ? We have 36 choices for each character, and they are all independent, so N = 366 .
What is Z? We have 26 choices for each character, and all the choices are independent, so Z = 266 .
Then D = 366 − 266 .
A similar process applies to 7 characters, and 8 characters. We then have the total number of
possible passwords, with either 6, 7, or 8 characters using at least 1 digit, is
which turns out to be a little under 3 trillion possibilities. (In fact: 2,684,483,063,360 .)
Some of these, however, include 123456 and letmein1.
(b) Suppose we choose a day of the week 100 times. For example: ‘Wed’, ‘Mon’, ‘Mon’, ‘Sun’, ‘Sat’
and so on. Prove that, no matter what sequence of days we choose (randomly or otherwise) to
write down, we must have written down at least one of the days of the week at least 15 times.
Solution: (2 marks) We will argue by contradiction. Suppose we have 100 days written down,
and every day (such as Wednesday) is written at most 14 times. Since there are 7 distinct days,
the maximum number of days written down is 7 × 14 = 98. Then we have 100 days written down,
and we have at most 98 days written down — contradiction. So the supposition that each day is
written down at most 14 times must be wrong. Hence there must be at least one day written down
at least 15 times.
(c) In how many different ways can the letters of REARRANGEMENT be arranged?
Solution: (2 marks) Re-label so as to make each letter distinctly different; we then have
R1 E1 A1 R2 R3 A2 N1 GE2 ME3 N2 T, giving 13 distinct objects which can be permuted in 13! ways.
Now, we have over-counted. For instance in a given arrangement of letters the 3Rs can be per-
muted in the original in 3! ways without change, so with respect to the Rs we have over-counted
by a factor of 3!. With respect to the Es, by another factor of 3!. With respect to the As, by 2!
2
13!
and the Ns also 2!. The correct number of distinct arrangements is then = 43,243,200
3! 3! 2! 2!
which is over 40 million ways.
(d) How many bit strings containing exactly eight 0s and twelve 1s have either all the 0s consecutive,
or have all the 1s consecutive?
Solution: (2 marks) Let’s count all the ways that the 0s can be consecutive. The first of the
block of 8 could be at the beginning, or from the second bit, or starting prior to, or at, the 13th
bit. So there are 13 ways to have all 0s consecutive. (Notice that two of these also have all 1s
consecutive.) •
◦
•◦
◦ • •
◦•◦
◦
• •
◦
For all the 1s consecutive, the first 1 could be at the beginning (that is, on the far ◦
• ◦
•
◦ ◦
left, or starting prior to or at the 9th position. So there are 9 ways — but 2 of these •
◦ ◦
•
◦ ◦
have already been counted, so only 7 new ones. Altogether then, there are 20 such ◦
•◦ ◦
◦◦
bit strings. This number seems suspicious, given there are 20 bits in our string.
Is there an easier way to do the counting? (See the image at right.)
(a) How many distinct solutions are there? Solution: (1 mark) Suppose we have 36 *s, and 4
partition symbols, such as ‘|’. Then if we put all these symbols in a row, we can have a particular
choice of a value assigned to x1 , x2 and so on. How many distinct ways are there of doing this?
There are 40 choices for which is the first partition symbol, then 39 (independent choices) for the
next, and so on, down to 37 choices for the last partition symbol. Altogether, 40 × 39 × 38 × 37
choices. However, these can be rearranged in 4! = 24 ways; hence we have over-counted by this
factor. (︃ )︃
40 40 × 39 × 38 × 37
Then the number of solutions is given by = = 91,390 .
4 4!
(b) How many distinct solutions are there if x1 ≥ 12 ? Solution: (1 mark) Let’s first allocate
12 to x1 , so the new problem becomes x1 + x2 + x3 + x4 + x5 = 24 with all the xs, as usual, being
non-negative.
(︃ )︃Then the number of solutions, computed as in part (a), is given by the binomial
28 28 × 27 × 26 × 25
coefficient = = 20,475 .
4 4!
(c) How many distinct solutions are there if x1 < 18 ? Solution: (1 mark) Let N denote the
number of ways we can have x1 ≥ 18. Since we (︃ know )︃ the number of ways without restriction (from
40
part (a)), the number of ways to have x1 < 18 is −N . Computing N in the manner of part (b),
(︃ )︃ 4 (︃ )︃ (︃ )︃
26 40 22
we find that N = . So the desired number of ways is − = 91,390−7,315 = 84,075 .
4 4 4
(d) How many distinct solutions are there if x1 < 18 and x2 < 6 ?
(︃ )︃
40
Solution: (2 marks) We know that is the number of solutions without restrictions. Let
4
A be the set of solutions where x1 ≥(︃18 ,)︃and let B be the set(︃of )︃
solutions where x2 ≥ 6 . Then the
40 ⃓ ⃓ 40
number of solutions for this part is − ⃓A ∪ B ⃓ , where = 91,390 .
4 4
By the Inclusion–Exclusion principle, we have
(︃ )︃ (︃ )︃ (︃ )︃
⃓A ∪ B ⃓ = |A| + |B| − ⃓A ∩ B ⃓ = 22 + 34 − 16 = 7,315 + 46,376 − 1,820 = 51,871 ,
⃓ ⃓ ⃓ ⃓
4 4 4
so the number of distinct solutions having x1 < 18 and x2 < 6 is 91,390 − 51,871 = 39,519 .
⃝
c Department of Mathematics & Statistics, Macquarie University.
3
Euclidean algorithm, Congruences, Minimal Spanning Trees
5. Let g be the greatest common divisor of 9883529 and 759345.
Find g using the Extended Euclid’s algorithm implemented via the ‘table method’, and hence find
integers x and y so that g = 9883529 x + 759345 y .
Solution: (4 marks) Finding successive quotients, and building the table, as described in lectures,
we get:
9883529 0 1
759345 1 0
12044 13 13 1
573 63 820 63
11 21 17233 1324
1 52 896936 68911
0 11 9883529 759345
so that g = 1 = 896936 × 759345 − 68911 × 9883529 ; thus x = −68911 and y = 896936 .
Using your answers to this as your starting point, do the following tasks.
(a) Find a solution of 3936 x ≡ d mod 1293. Solution: (1 mark) Just take the x found
already: namely x = −68, so that − 68 × 3936 = 3 − 207 × 1293.
The set of all solutions is characterised as x ≡ 363 mod 431, but this was not asked for.
(b) Find an integer r that has the property that r ≡ d mod 1293 and r ≡ 0 mod 3936.
Solution: (1 mark) Take r = −68 × 3936 = −267,648, which satisfies r = 3 − 207 × 1293 ≡
3 mod 1293. Alternatively use r = (1293 − 68) × 3936 ≡ 1,428,768 mod 1,696,416 .
Any number satisfying r ≡ 1428768 mod lcm(1293, 3936) = 1696416 is a valid solution.
(c) Find an integer R that has the property that R ≡ 126 mod 1293 and R ≡ 0 mod 3936.
Solution: (1 mark) Since 126 = 3 × 42 then take R = 42 r = −11,241,216 .
Alternatively use R = 633,696 mod 1,696,416.
(d) Find an integer s that has the property that s ≡ d mod 3936 and s ≡ 0 mod 1293.
Solution: (1 mark) Take s = 207 × 1293 = 3 + 68 × 3936 ≡ 3 mod 3936; so s = 267,651 .
Any number satisfying s ≡ 267651 mod 1696416 is a valid solution.
(e) Find an integer S that has the property that S ≡ 573 mod 3936 and S ≡ 0 mod 1293.
Solution: (1 mark) Since 573 = 3 × 191 then take S = 191 s = 51,121,341 ≡ 228,861 mod
1,696,416 .
(f) Find an integer T that has the property that T ≡ 126 mod 1293 and T ≡ 573 mod 3936.
Solution: (1 mark) Using the Chinese Remainder Theorem, we take T = R+S = 39,880,125
≡ 862,557 mod 1,696,416 .
(g) Is T the only number satisfying those two congruences; if not, which other numbers?
Solution: (1 mark) In fact any number 862,557 + 1,696,416 k with k ∈ Z will also work.
4
7. [from 2014 final exam]
(a) Verify that 321 is expressed in binary as 101000001.
Solution: (1 mark) 1010000012 = 1 + 26 + 28 = 1 + 64 + 256 = 321 in decimal.
(b) Starting at the left-hand end, write down the 9 decimal integers that result from taking succes-
sively extra digits in this binary expansion.
Solution: (1 mark) Appending successive binary digits from the left: 1, 102 ↦→ 2, 1012 ↦→ 5,
10102 ↦→ 10, 101002 ↦→ 20, 1010002 ↦→ 40, 10100002 ↦→ 80, 101000002 ↦→ 160, 1010000012 ↦→ 321 .
Thus the 9 decimal numbers are: 1, 2, 5, 10, 20, 40, 80, 160, 321.
(c) We wish to calculate the congruence class of 4517321 modulo 3187. Using the previous part,
describe the calculations that you would perform to determine this congruence class.
Solution: (1 mark) Since 4517 ≡ 1330 (mod 3187), we will calculate successively the powers:
13302 , 13305 , 133010 , 133020 , 133040 , 133080 , 1330160 , 1330321 , each modulo 3187 .
(d) Do those calculations, using your calculator. What is 4517321 modulo 3187 ?
(Do not use sophisticated software, as this will not be available to you under exam conditions.)
Solution: (3 marks) We get successively:
13302 = 1768900 = 115 (mod 3187)
13305 = (13302 )2 × 1330 = 1152 × 1330 = 13225 × 1330 = 17589250 = 197 (mod 3187)
10 5 2 2
1330 = (1330 ) = 197 = 38809 = 565 (mod 3187)
133020 = (133010 )2 = 5652 = 319225 = 525 (mod 3187)
40 20 2 2
1330 = (1330 ) = 525 = 275625 = 1543 (mod 3187)
133080 = (133040 )2 = 15432 = 2380849 = 160 (mod 3187)
160 80 2 2
1330 = (1330 ) = 160 = 25600 = 104 (mod 3187)
321 160 2 2
1330 = (1330 ) × 1330 = 104 × 1330 = 10816 × 1330 = 14385280 = 2349 (mod 3187)
Only the parts shown in red need be calculated; this can be done easily on a calculator, using
a single memory register to help do the reductions modulo 3187 . The technique was shown in
lectures. The final answer is that 4517321 = 2349 (mod 3187) .
8. The table below has the information to characterise a weighted complete (undirected) graph. Num-
bers in the table give the weight of the edge joining each pair of vertices. Use Prim’s algorithm to
find a minimal spanning tree in this weighted graph. Give the order in which edges are added to
the tree.
b c d e f g h
a 18 4 37 93 28 46 55
b 47 12 9 51 72 63
c 65 82 11 44 33
d 94 17 61 56
e 29 73 38
f 31 5
g 59
⃝
c Department of Mathematics & Statistics, Macquarie University.