0% found this document useful (0 votes)
36 views18 pages

Exam cs120 2019 S2+solutions

The document is an exam for a computer science course on mathematics. It contains 15 multiple choice and short answer problems testing concepts in discrete mathematics. The exam instructions specify a two hour time limit, show all work, and do not allow calculators or notes. The first 12 problems are multiple choice worth one mark each, and the remaining 3 are short answer or proof-based problems.

Uploaded by

Henry Xu
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)
36 views18 pages

Exam cs120 2019 S2+solutions

The document is an exam for a computer science course on mathematics. It contains 15 multiple choice and short answer problems testing concepts in discrete mathematics. The exam instructions specify a two hour time limit, show all work, and do not allow calculators or notes. The first 12 problems are multiple choice worth one mark each, and the remaining 3 are short answer or proof-based problems.

Uploaded by

Henry Xu
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/ 18

VERSION 1

Question/Answer Booklet
ID#: COMPSCI 120

THE UNIVERSITY OF AUCKLAND

SEMESTER TWO 2019


Campus: City

COMPUTER SCIENCE

Mathematics for Computer Science

(Time allowed: TWO hours)

Write your first name here:


Write your last name here:
Write your UPI here:
Write your ID# here:

NOTE:

• This exam will begin with 10 minutes of reading time. You may not write anything
in this time.

• There are 15 problems, on pages 3 to 12 . The total number of marks is 24 .


Attempt all of the questions; there is no penalty for incorrect answers, and many
problems have partial credit!

• There is more than enough space for an answer to every problem in this booklet. If
you find yourself running out of space, this may be a sign that you are overthinking
things!

• Show all working, and place all answers in this booklet. For multiple-choice problems,
please circle your answers in this booklet. Do not remove any pages from this booklet!

• Pages 13 through 18 of this exam are left blank, to give you additional paper to
work on. They will not be marked.

• No calculators or notes are allowed.

• Best of luck!

Page 1 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 2 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

Multiple-choice.
Problems 1-12 on this exam are multiple-choice questions. Each problem is worth one mark,
and there is exactly one correct answer for each question. No justification is needed, just
circle the correct answer.
1. Suppose that p and q are odd integers. Consider the following two statements, and
decide whether they are true or false:

Statement A (p + 3q)(p + 4q) must be even.


[1 mark]
Statement B p3 − q 3 − q could be even.

(a) Only Statement A is true (c) Both statements are true


(b) Only Statement B is true (d) Neither statement is true

2. Suppose n is a natural number and that n divides 28. Which of the following must be
true?
[1 mark]
(a) n divides 56
(b) Either n divides 4 or n divides 7
(c) Either 4 divides n or 7 divides n
(d) n must be one of the following numbers: 2,4,7, or 14

3. Suppose that s is the string HONESTLY. Let

A = {t | t is a substring of s and the length of t is strictly less than 4}.

What is |A|? [1 mark]


3
 8
+ 21 82 + 11 81 + 8
    
(a) 6 + 7 + 8 + 1 (c) 1 3 0

8 8 8 8
8! 8! 8! 8!
(d) + + +
   
(b) 3
+ 2
+ 1
+ 0 3! 2! 1! 0!

Page 3 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

4. What is the probability that a randomly chosen two-digit natural number has two
distinct digits and is odd? Recall that the first digit of any such number is at least 1.
[1 mark]
4 2 9 1
(a) 9
(b) 5
(c) 20
(d) 2

5. How many functions f : X → Y with X = {a, b} and Y = {u, v} are there?


[1 mark]

(a) 4 (b) 2 (c) 8 (d) 1

6. Suppose that we have two sorting algorithms, called algorithm A and algorithm B,
with runtimes as follows:

The number of steps algorithm A takes to sort a list of n things is n2 + 2 steps.


The number of steps algorithm B takes to sort a list of n things is 12n log2 (n) steps.

Which of the following accurately compares the performance of these algorithms when
sorting a list of n things, for a large value of n?
[1 mark]
(a) Algorithm B is faster than algorithm A, because n2 + 2 grows faster than 12n log2 (n).
(b) Algorithm A is faster than algorithm B, because n2 + 2 grows faster than
12n log2 (n).
(c) Algorithm B is faster than algorithm A, because 12n log2 (n) grows faster than
n2 + 2.
(d) Algorithm A is faster than algorithm B, because 12n log2 (n) grows faster than
n2 + 2.

Page 4 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

7. Suppose G is a graph. Which of the following must be true?


[1 mark]
(a) G has an even number of vertices with odd degree
(b) G has an odd number of vertices with even degree
(c) G has at least one vertex with even degree
(d) G has at least one vertex with odd degree

8. Suppose that you are buying vegetables from a shop which sells three kinds: parsnip,
carrot, and onion. You wish to buy a total of six vegetables. How many different ways
are there to do so (assuming that any vegetables of the same kind are identical)?
[1 mark]

(a) 28 (b) 6 (c) 32 (d) 56

9. Suppose that you wish to show that there is a graph with 10 vertices and 20 edges
which is not connected. Which of the following proof methods is best suited to this
task?
[1 mark]
(a) Proof by construction
(b) Proof by induction on the number of edges in the graph
(c) Proof by cases
(d) Proof by induction on the number of vertices in the graph

Page 5 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

10. Consider the following claim: if n is any natural number, then n2 ≡ 0 (mod 3) or
n2 ≡ 1 (mod 3).
Here is a proof of the claim.
Because n is a natural number, either n ≡ 0 (mod 3), n ≡ 1 (mod 3), or
n ≡ 2 (mod 3).
If n ≡ 0 (mod 3), then n2 ≡ 02 (mod 3), so n2 ≡ 0 (mod 3).
If n ≡ 1 (mod 3), then n2 ≡ 12 (mod 3), so n2 ≡ 1 (mod 3).
If n ≡ 2 (mod 3), then n2 ≡ 22 (mod 3), so n2 ≡ 4 (mod 3). But 1 ≡ 4 (mod 3),
which means n2 ≡ 1 (mod 3).
Thus we see that either n2 ≡ 0 (mod 3), or n2 ≡ 1 (mod 3).
Which method is being used to prove the claim? [1 mark]

(a) Proof by cases (c) Proof by counting


(b) Proof by contradiction (d) Proof by induction

11. Suppose you are trying to negate the statement “if x and y are nonzero integers, then
xy is also nonzero”. Which of the following is a negation of the statement?
[1 mark]
(a) There are nonzero integers x and y such that xy = 0.
(b) If x = 0 and y = 0, then xy = 0.
(c) If x and y are not integers, then xy is also not an integer.
(d) If at least one of x and y is zero, then xy 6= 0.

12. Which of the following statements is best suited to being proved by induction?
[1 mark]
3n + 1
(a) If a0 = 1 and an+1 = 3an − 1 for each n ≥ 0, then an = for each natural number n.
2
(b) There are two irrational numbers whose product is rational.
(c) For each real number a, the equation x2 + ax − 1 = 0 has 2 solutions.
(d) If p and q are two prime numbers, pq + p + q + 1 is not prime.

Page 6 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 7 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

Arguments.
Problems 13, 14, and 15 on this exam are free-response proof-based problems. For these
problems, it is not enough to just have the right answer: you need to prove that the
statements are correct! With that said, we may give partial marks for attempts at these
problems even if they aren’t fully rigorous proofs. As a result, even if you don’t think you
can come up with a complete argument, do try to explain in your own words what you think
is going on! Describe the definitions that you think are relevant, talk about ideas that you
think might lead to the solution eventually, and otherwise give it your best shot.

n(n−1)
13. Use mathematical induction to show that a complete graph with n vertices has 2
edges.
(A correct or partially correct proof that does not use mathematical induction results
in zero marks.)
[4 marks]

If n = 1, then the result holds because the complete graph on one vertex has
0 = 1(1−1)
2
edges. Assume that the complete graph on k vertices has k(k−1) 2
edges.
The complete graph on k + 1 vertices can be obtained from the complete graph on
k vertices by adding a new vertex v and connecting it to each other vertex. This
requires k new edges. Hence, we have that the number of edges in the complete
2
graph on k + 1 vertices is k(k−1)
2
+ k = k −k+2k
2
= k(k+1)
2
. This establishes the claim.

Page 8 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 9 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

14. Suppose that T is a tree. Suppose also that for each vertex v of T , the degree of v is
either 1 or 3.
Let A be the set of vertices of degree 1 in T , and let B be the set of vertices of degree
3 in T .
Show that |A|=|B|+2.
[4 marks]

Say there are k vertices of degree 1 and l of degree 3. Then there are k + l − 1
edges, because a tree with n vertices has n − 1 edges. By the degree sum for-
mula/handshaking lemma, the sum of the degrees of vertices is 2k + 2l − 2. But on
the other hand, the sum of degrees is k + 3l. So we have k + 3l = 2k + 2l − 2 and
hence k = l + 2. So there are 2 more vertices of degree 1 than there are vertices of
degree 3.

Page 10 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 11 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

15. Show that log5 (4) is an irrational number.


[4 marks]

x
If the number is not irrational, then let = log5 (4), where x and y are integers.
y
Note that both
x
x and y can be taken to be positive, because log5 (4) > log5 (1) = 0.
We have 5 y = 4, and thus 5x = 4y . But this means that the left hand side is a
positive power of 5 (hence odd) and the right hand side is a positive power of 4
(hence even).
So 5x and 4y cannot be equal! This gives us the contradiction we wanted, and
shows that log5 (4) is indeed irrational.

Page 12 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 13 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 14 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 15 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 16 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 17 of 18
VERSION 1
Question/Answer Booklet
ID#: COMPSCI 120

This page is intentionally left blank.

Page 18 of 18

You might also like