You are on page 1of 7

SGDM E2013 Discrete Mathematics

January 2014
Final Exam
Name: Answer Key
Instructions. (50 points) This exam consists of open ended questions and also multiple choice
questions. Write all your answers on the separate carbon paper. In multiple choice questions,
you are requested to choose the correct answer from the options listed, but also to include a
brief justication (or calculation, if any) for your chosen answer.
(3
pts
) 1. Prove that the following two formulas are tautologies:
i) ((p q) (p q)) p
ii) ((x.(Q(x) P(x))) y.P(y))
Solution: For the rst formula we use a truth table:
p q p q p q (p q) (p q) ((p q) (p q)) p
T T T T T T
T F F F T T
F T T F F T
F F T F F T
and for the second one we use the denition of the negation of propositional connectives
and quantiers, so that we have:
((x.(Q(x) P(x))) y.P(y)) (x.(Q(x) P(x))) (y.P(y))
(x.(Q(x) P(x))) (y.P(y))
(x.(Q(x) P(x))) (y.P(y))
Then we can see that there are two possibilities. First, if we have y.P(y), then the formula
is valid. In the other case, we have y.P(y), and therefore y.(Q(y) P(y)), so that
the formula is also valid.
(3
pts
) 2. Consider the function f inductively dened as follows:
f(0) = 1, f(1) = 1, f(2) = 2,
and f(n) = f(n 1) f(n 3) for any n 3
This is an inductive denition with three base cases, we can consider some small values for
n to get an idea of what f does, and we can prove some properties of f by induction.
i) compute f(3), f(4) and f(5),
ii) prove that for any n 2, the value f(n) is an even number.
Solution: The values for n = 3, 4, 5 are the following:
f(3) = f(2) f(0) = 2 1 = 2
f(4) = f(3) f(1) = 2 1 = 2
f(5) = f(4) f(2) = 2 2 = 4
To prove that f(n) is even for any n 2, it is sucient to use a simple induction on n.
The base case happens when n = 2, and the result is immediate since f(2) = 2 which
is even. Then, in the general case, we have f(n) = f(n 1) f(n 3) and f(n 1) is
even by induction hypothesis. Therefore, f(n) must be even. Using a strong induction is
also possible, but unnecessary since the multiplication of an even number by any number
is even.
SGDM E2013 Discrete Mathematics/Final Exam Page 2 of 7
(4
pts
) 3. Full binary trees are inductive structures dened by one base element and one constructor
with two arguments, denoted by L and N respectively, which represent leaves and internal
nodes. The set B of full binary trees is thus dened by:
L B and N(T
1
, T
2
) B if T
1
B and T
2
B
The root of such a tree is either L if the tree has only one node, or the node N(T
1
, T
2
) such
that all other nodes of the tree are contained in T
1
or T
2
. A branch is a path from the root
to some leaf. The height of a full binary tree T, denoted by h(T), is dened as the number
of nodes found in the longest branch of T, excluding the root. For example, the height of
N(L, N(L, L)) is 2. Finally, we denote by n(T) the number of nodes (both leaves and internal
nodes) in a full binary tree T.
i) given inductive denitions for h(T) and n(T) for any T,
ii) prove that for any full binary tree T we have h(T) < (n(T) + 1)/2.
Solution: The inductive denitions for h(T) and n(T) are:
h(L) = 0 h(N(T
1
, T
2
)) = max(h(T
1
), h(T
2
)) + 1
n(L) = 1 n(N(T
1
, T
2
)) = n(T
1
) +n(T
2
) + 1
Then, to prove that for any T we have h(T) < (n(T)+1)/2, we use a structural induction on
T. The base case happens when T contains only one node, so that h(T) = 0 < 1 = n(T). In
the general case, by induction hypothesis h(T
1
) < (n(T
1
) +1)/2 and h(T
2
) < (n(T
2
) +1)/2,
so that we can conclude by considering the two possible cases. If h(T
1
) > h(T
2
) then we
have:
h(T) = h(T
1
) + 1 < ((n(T
1
) + 1)/2) + 1
< (n(T
1
) + 3)/2
< (n(T
1
) +n(T
2
) + 2)/2
< (n(T) + 1)/2
since we have n(T) 1 for any T and thus in particular n(T
2
) 1. The other case, when
h(T
2
) h(T
1
) is the same except that we start from h(T
2
) and n(T
2
).
(3
pts
) 4. Suppose f : Z
+
{0, 1, 2, 3} satises
f(j) =

0 if 7 j, 3 | j,
1 if 7 | j, 3 j,
2 if 21 | j,
3 otherwise
where Z
+
= {0, 1, 2, . . .} is the set of positive integers, a | b denotes that a divides b, and
a b denotes that a does not divide b.
(a) f is a bijective function
(b) f is not a function
(c) f is a function which is neither one-to-one nor onto
(d) f is a function which is not one-to-one, but it is onto
Solution: f is a function because each value in the domain Z
+
has at most one image in
the codomain {0, 1, 2, 3}. It is onto because all values in the codomain {0, 1, 2, 3} are the
image of some element in the domain, and it is not one-to-one because there are more than
one element in the domain having the same image.
SGDM E2013 Discrete Mathematics/Final Exam Page 3 of 7
(2
pts
) 5. The rst term of an arithmetic progression is a
0
= 1, and we also know that the term a
11
is a
11
= 23. Find the term a
20
of the progression.
(a) a
20
= 39
(b) a
20
= 41
(c) a
20
= 42
(d) There is not enough information.
Solution: Every term is dened as a
n
= a + nd in an arithmetic progression. From a
0
=
1 = a + 0 d we know that a = 1, and from a
11
= 23 we know that 1 + 11 d = 23, that is,
d = 2. Therefore, a
20
= 1 + 20 2 = 41.
(2
pts
) 6. Given the following relations on the set {1, 2, 3, 4},
R
1
= {(1, 1), (2, 2), (3, 3), (4, 4)}
R
2
= {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}
R
3
= {(1, 1), (1, 2), (1, 4), (2, 2), (2, 4), (3, 3), (4, 1), (4, 2), (4, 4)}
(a) R
2
and R
3
are transitive
(b) R
1
and R
2
are equivalence relations
(c) R
3
is symmetric but not transitive
(d) None of the above solutions
Solution: The answers (a) nor (c) are incorrect because R
3
is neither transitive (because
of having the elements (2, 4) and (4, 1), the element (2, 1) should also be in the relation for
R
3
to be transitive) nor symmetric (because of having the element (1, 2), again the element
(2, 1) should be in the relation for R
3
to be symmetric). But the answer (b) is correct:
both relations R
1
and R
2
are symmetric, transitive and reexive, thus they are equivalence
relations.
(3
pts
) 7. Let R = {(1, 2), (2, 3), (3, 4)} be a relation on the set {1, 2, 3, 4}. What is the transitive
closure of R?
(a) {(1, 2), (2, 3), (3, 4), (2, 1), (3, 2), (4, 3)}
(b) {(1, 2), (2, 3), (3, 4), (1, 3), (2, 4)}
(c) {(1, 2), (2, 3), (3, 4), (1, 3), (2, 4), (1, 4)}
(d) {(1, 2), (2, 3), (3, 4), (1, 4)}
Solution: Because of having the elements (1, 2) and (2, 3), then the element (1, 3) should be
in the transitive closure. From the elements (2, 3) and (3, 4), also the element (2, 4) should
be in the transitive closure. Finally, from the elements (1, 2) and (2, 4), we have that the
element (1, 4) should also be in the transitive closure.
(3
pts
) 8. Six presidents from the countries A, B, C, D, E and F are attending an important in-
ternational event. The event is coming to an end, and they want to decide which one of
them will organize the next event. They want the next organizer to be in harmony with
the highest number of presidents as possible. For this reason, they decide to choose that
president having met with more presidents.
President A claims to have had 1 meeting with some other president, president B claims to
have met with 2 other presidents, president C claims to have had 3 meetings, president D
claims 2 meetings, president E claims 4 meetings and, nally, president F claims to have
had 3 meetings. In this context, a meeting is always assumed to be one-to-one. Clearly,
president E seems to be the next organizer of the international event. But... has anyone
cheated? Consider justifying the answer in terms of graphs. Be brief but precise.
Solution: We can represent this exercise as a simple graph in which each president is
a vertex and an edge between vertices A and B represents a meeting between president
SGDM E2013 Discrete Mathematics/Final Exam Page 4 of 7
A and president B. This means that the number of meetings that each president has
had corresponds to the degree of the vertex representing that president. Therefore, this
problem is asking whether there exist a graph having |V | = 6, and whose vertices have
degrees 4, 3, 3, 2, 2, 1. By the Handshake Theorem, this graph cannot exist because the sum
of the degrees of all vertices should be an even number. This means that some president has
cheated when claiming how many meetings he had. Note that there is no way of knowing
who of them cheated, and it might have been the case that more than one did.
(2
pts
) 9. A connected and planar graph having 15 vertices divides the plane into 12 regions. What
is the number of edges connecting the vertices in this graph?
(a) 15
(b) 24
(c) 25
(d) There is not enough information.
Solution: We use here Eulers formula R = E V + 2, where R is the number of regions,
E is the number of edges, and V the number of vertices of the graph.
(2
pts
) 10. Consider the alphabet = {a, b, c} and the language L on dened as the following set:
{ (a +b)
n
c
k
a
n+1
| n, k N}
where (a + b) denotes a symbol that is either a or b, as in regular expressions. Note that
to be more formal we could write { w | n, k N, w (a +b)
n
c
k
a
n+1
} to describe the same
language, thus formally using regular expressions. Which one of the following grammars
in BNF (all with initial symbol S, and where is the empty string) generates exactly the
words of this language?
(a) S ::= Ra R ::= aRa | bRa | Q Q ::= cQ |
(b) S ::= R | Q R ::= aRa | bR | Q Q ::= Qc | a
(c) S ::= aS | bS | R R ::= cR | Q Q ::= aR | a
(d) S ::= R | Q R ::= aS | bS Q ::= Rc | Ra
Solution: A good methodology is to proceed by elimination. First, the grammar (d) is not
terminating because all of its productions contain at least one non-terminal symbol (so it is
impossible to produce any nite word). Then, in grammar (c), we can obtain the following
derivation:
S R cR cQ caR cacR cacQ caca
thus producing a word that is not in the given set (since it contains an alternance of a and
c symbols). Finally, using grammar (b) we can obtain the derivation:
S R bR bQ ba
wich ends in a word that is not in the given set (there should be one more a for the count
described by n and n + 1 to match). We can therefore conclude that (a) is the right
grammar, where S guarantees the presence of the last a and R introduce always as many
a or b at the begininng as a at the end, while Q is only concerned with the introduction of
an arbitrary number of c symbols.
SGDM E2013 Discrete Mathematics/Final Exam Page 5 of 7
(4
pts
) 11. Write a deterministic nite-state automaton that accepts a word w on the alphabet {0, 1}
if and only if w has the following shape:
1
odd number of 0s

0 0 1
odd number of 0s

0 0 1
odd number of 0s

0 0 1
that is, if w ends with a 1 and is otherwise composed of arbitrarily many blocks formed of
a 1 followed by an odd number of 0s (for example, the words 1000101 and 1010000010001
are accepted, but neither 10001101 nor 1001000001).
Solution: We describe the automaton by its transitions (s
c
, e, s
d
), where s
c
is the current
state, e is the symbol read and s
d
is the destination state. These transitions are:
(s
0
, 1, s
1
) (s
1
, 0, s
2
) (s
2
, 0, s
3
) (s
2
, 1, s
1
) (s
3
, 0, s
2
)
and its initial state is s
0
, the unique accepting state being s
1
. The idea is that the word can
be a single 1, so after reading 1 we get to s
1
which is an accepting state, and any additional
block 0 01 is treated by states s
2
and s
3
, which are simply ensuring that an even number
of 0 are read before a 1 leads back to s
0
.
(4
pts
) 12. Consider a Turing machine using the alphabet {0, 1, } and the blank symbol B, described
by the following transitions, represented as ve-tuples (which give the source state, the
input, the destination state, the output and the direction):
(s
0
, 0, s
1
, , L) (s
0
, 1, s
2
, , L) (s
0
, , s
0
, , R) (s
0
, B, s
4
, B, L)
(s
1
, , s
1
, , L) (s
1
, 0, s
1
, 0, L) (s
1
, 1, s
1
, 1, L) (s
1
, B, s
3
, 0, R)
(s
2
, , s
2
, , L) (s
2
, 0, s
2
, 0, L) (s
2
, 1, s
2
, 1, L) (s
2
, B, s
3
, 1, R)
(s
3
, 0, s
3
, 0, R) (s
3
, 1, s
3
, 1, R) (s
3
, , s
0
, , R)
(s
4
, , s
4
, B, L)
This machine has 5 states, the initial state being s
0
. It expects a tape containing a string of
0s and 1s only in the beginning, the rest being blank, and the initial position is the leftmost
non-blank symbol, as usual. Given the following tape on which we run the machine:
| B | B | 0 | 1 | 1 | B | B |
what is the conguration of the tape after the machine stops?
(a) | B | B | 1 | | 1 | B | B |
(b) | B | B | 1 | 1 | 0 | B | B |
(c) | B | B | 0 | 0 | 1 | B | B |
(d) The machine never reaches a halting conguration.
Solution: The only way is to perform the actions of the machine, step by step. One can
observe after a few steps that the machine reads either 0 or 1, replaces it with and writes
the number somewhere else on the left. This is repeated and when reading numbers further
on the right it must move further on the left to nd a blank space to write the number.
When all three numbers have been moved, they are placed in reverse order and three
symbols are left in the original cells. The last phase cleans up the tape by replacing these
with the blank symbol, and stops in state s
4
when it reaches the rst non-blank symbol
(the rightmost number in the resulting reversed string of 0 and 1).
SGDM E2013 Discrete Mathematics/Final Exam Page 6 of 7
(3
pts
) 13. Recall that an ISBN-10 is a 10-digit code x
1
x
2
. . . x
10
used to identify a book uniquely,
satisfying
10

i=1
ix
i
= 0 (mod 11).
The last digit, x
10
, is called check digit. The rst nine digits of the ISBN-10 of a book are
071954400, what is the check digit?
(a) 0
(b) 9
(c) 10 (X)
(d) This ISBN-10 is not valid.
Solution: 0 1 + 7 2 + 1 3 + 9 4 + 5 5 + 4 6 + 4 7 + 0 8 + 0 9 +x 10 0 (mod 11)
Then we have 130 +x 10 0 (mod 11)
9 +x 10 0 (mod 11)
Therefore, the check digit is x = 9.
(2
pts
) 14. What is the least common multiple of 540 and 216?
(a) 2
5
3
6
5
(b) 2
2
3
3
5
(c) 2
2
3
2
5
2
(d) 2
3
3
3
5
Solution: lcm(540, 216) = lcm(2
2
3
3
5, 2
3
3
3
) = 2
max{2,3}
3
max{3,3}
5
max{1,0}
= 2
3
3
3
5
(3
pts
) 15. Paul wants to send a set of 12 dierent symbols and 40 blank spaces through a communi-
cation channel. These blank spaces should be sent in such a way that there is at least 3
blank spaces between any two consecutive symbols, and no spaces are allowed before the
rst symbol or after the last symbol. How many dierent ways does he have of sending a
message?
(a)

17
10

12!
(b) 3

40
12

(c)

11
7

(d)

18
11

Solution: Since at least 3 blank spaces should be sent between any two consecutive symbols,
and there are 12 symbols, we do have 11 wholes between every symbol, which will contain
3 blank spaces each. The remaining 40 33 = 7 blank spaces will have to be spread all
over the 11 wholes, and there are

11+71
7

17
7

dierent ways of doing so. Note that

17
7

17
177

17
10

. Finally, for each dierent way of arranging the blank spaces, we also
have 12! dierent ways (dierent orders) of sending the 12 symbols. By the product rule,
Paul has

17
10

12! dierent ways of sending a message.


(2
pts
) 16. The owner of a pizzeria prepares every pizza by always combining 4 dierent ingredients.
How many ingredients does he need, at least, if he would like to oer 30 dierent pizzas in
the menu?
(a) 6
(b) 7
(c) 8
(d) 9
SGDM E2013 Discrete Mathematics/Final Exam Page 7 of 7
Solution: Using 6 dierent ingredients, he can obtain

6
4

= 15 dierent pizzas, while with


7 ingredients he gets

7
4

= 35 dierent pizzas. Then, since

6
4

30

7
4

, he needs at
least 7 ingredients.
(3
pts
) 17. A car pool contains 8 Fords (4 red and 4 white) and 12 Pontiacs (2 red and 10 white).
You are allocated a car at random. You see from a distance that it is red. What is the
probability that you have been given a Ford?
(a) 0.240
(b) 0.375
(c) 0.667
(d) 0.833
Solution: Let F and R be the event of being a Ford and a red car, respectively. We are
asked for P(F|R). There are 20 cars of which 8 are Fords, so P(F) =
8
20
= 0.4, and 6
cars are red, so P(R) =
6
20
= 0.3. The probability of a red car, given that it is a Ford, is
P(R|F) =
4
8
= 0.5. So
P(F|R) =
P(F)P(R|F)
P(R)
P(F|R) =
0.40.5
0.3
= 0.667
We could have also used Bayes theorem for this exercise.
(2
pts
) 18. A professor randomly selects three new teaching assistants from a total of 10 applicants: 6
male and 4 female students. The probability that no females are hired is
(a) 0.167
(b) 0.200
(c) 0.250
(d) 0.333
Solution: There are

10
3

= 120 dierent ways of picking 3 TAs out of 10 candidates, and

6
3

= 20 dierent ways of picking 3 men out of the total of 6 male candidates. Thus the
probability that no females are hired is 20/120 = 0.167.

You might also like