COMPSCI120-2021-S1-exam Solutions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

COMPSCI 120

THE UNIVERSITY OF AUCKLAND

SEMESTER 1, 2021
Campus: City

COMPUTER SCIENCE/MATHEMATICS

Mathematics for Computer Science

(Time allowed: 60 minutes)

Write your name here:


Write your UPI here:
Write your ID# here:

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

• There are ?? problems, on pages ?? to ??. The total number of marks is ??. Attempt
all of the questions; there is no penalty for incorrect answers.

• Write all answers in this test booklet; work not written in the test booklet will not be
marked.

• 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!

• Pages ?? through ?? of this test are left blank, to give you additional paper to work
on.

1. Which of the following statements is TRUE?

(a) Let x, y be positive even numbers. Then xy is odd.


(b) If p is prime, then p2 + 1 is also prime.
(c) The product of three rational numbers is a rational number. ANSWER
(d) Let a, b be integers. If ab is a multiple of 25, then 25 is factor of a.

[1 mark]

Page 1 of ??
COMPSCI 120

2. Consider the following 3 strings over the alphabet {a, b} :

S = aaaaa, T = abbb, R = bbbbb.

Which of the following statements is TRUE?

(a) There are exactly 6 distinct substrings of S. ANSWER


(b) Suppose t is the number of distinct prefixes of T and r is the number of distinct prefixes
of R. Then t − r = 1.
(c) There are exactly 11 distinct prefixes of the word ST.
(d) There are exactly 5 distinct suffixes of R.

[1 mark]

3. Consider two sets

X = {∅, 3, {3}} and Y = {y| y is a subset of {1, 2, 3}}

Which of the following statements is TRUE?

(a) 3 ⊆ X
(b) ∅ ⊆ Y ANSWER
(c) 3 ∈ X ∩ Y
(d) ∅ ∈
/ X ∪Y

[1 mark]

4. Decide which of the following rules defines a function with domain and codomain equal to
R:
1
f (x) is y such that y 3 = 2 .
x
g(x) is y such that y = x3 .
2

(a) Only f.
(b) Only g.
(c) f and g.
(d) f and g are not functions. ANSWER

[1 mark]

Page 2 of ??
COMPSCI 120

5. You want to prove the following claim by contradiction:

Claim: Suppose G is a graph. If there is a circuit C such that C contains every edge of G
exactly once, then the degree of every vertex of G is even.

Which of the following assumptions is a correct start of your proof?

(a) Assume, that G does not have a circuit C such that C contains every edge of the graph
exactly once.
(b) Assume, that the degree of every vertex in G is odd.
(c) Assume, that there is at least one vertex in G with an odd degree. ANSWER
(d) All the other statements are incorrect

[1 mark]

6. Consider the following algorithm:

Input: a positive integer n.


(1) Set i to 1.
(2) If n < 3, then stop and print i. Otherwise go to (3).
n
(3) Increase i by 1. Update the value of n to be the integer part of . Go to (2).
3

Which statement is TRUE?

(a) The algorithm goes through step (3) roughly log3 (n) times. ANSWER
(b) The algorithm outputs 2 on input n = 10.
(c) The algorithm outputs the greatest k, such that n ≥ 3k .
(d) There is at least one input value for which the algorithm never terminates.

[1 mark]

7. Let a, b, m, n ∈ Z with m, n > 0. Which of the following statements is TRUE?

(a) If a ≡ b mod n, then a ≡ 4b mod n.


(b) If m | n and a ≡ b mod n, then a ≡ b mod m. ANSWER
(c) If a ≡ b mod n, then am ≡ bn mod n.
(d) If a ≡ b mod n, then a + b ≡ b mod n.

[1 mark]

8. Which of the following statements is TRUE?

Page 3 of ??
COMPSCI 120

n! + 1
(a) lim =0
n→∞ n100 + 100000000
n7 log2 (n) + 5n + 1 7
(b) lim 8
=
n→∞ n + 3n + 2 8
(c) The function f (n) = 5n + n4 grows faster than the function g(n) = 2n6 + n3 .
6

(d) The function f (n) = 2n grows faster than the function g(n) = n2000 . ANSWER
[1 mark]

9. A rugby team is posing for a photo after winning the grand final. There are 15 players and
one coach. The photographer needs to arrange them in two rows of 8. The coach, captain
and vice captain must all sit in the front row, and they must sit next to each other in three
adjacent chairs. The other players can sit anywhere.
How many possible ways are there to seat everybody?
(a) 16!
(b) 36 · 13! ANSWER
8! · 13!
(c)
5!
16

(d) 8
[1 mark]

10. Which of the following statements about trees is TRUE?


(a) There is a tree on 12 vertices with 3 vertices of degree 1, 3 vertices of degree 2, 3 vertices
of degree 3, and 3 vertices of degree 4.
(b) There is a binary tree of height 3 with 16 vertices.
(c) For every positive integer n, there exists a tree on n vertices with exactly 2 leaves.
(d) Let T = (V, E) be a tree. Let e be any edge in T , and let T 0 be the graph with vertex
set V and edge set E \ {e}. Then T 0 is not connected. ANSWER
[1 mark]

11. Consider the following claim and its proof: there is a prime number p such that p + 2, p + 4
and p + 8 are also prime numbers.

Proof: Let p = 3. Then p is a prime, and p + 2 = 5, p + 4 = 7 and p + 8 = 11 are also


primes. Therefore, the claim is true.

Which method is being used to prove the claim?


(a) Proof by induction.
(b) Proof by contradiction.
(c) Proof by construction. ANSWER
(d) Proof by cases.

Page 4 of ??
COMPSCI 120

[1 mark]

12. Which of the following statements can be proved using a proof by cases?
(a) If n is a natural number then n2 % 4 is equal to either 0 or 1. ANSWER

(b) 2 is irrational.
(c) If G is a graph on at least 2 vertices, then G contains 2 vertices whose degrees are equal.
n(n+1)
(d) The sum of the first n positive integers is 2
.
[1 mark]

Page 5 of ??
COMPSCI 120

Arguments.
There is one argument-based question on this test. You are asked to write a convincing
argument to show that the claim is true. We give out partial credit for good-faith
attempts. As a result, even if you don’t think you have a full and rigorous 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.

13. Consider an alphabet Σ formed using the first five letters of your Student UPI. (Example:
If your Student UPI is abcd123, Σ = {a, b, c, d, 1}. )
Let A be the set of all strings formed using Σ of length at most |Σ|. Assuming you don’t
care about the order in which the strings are chosen, find the number of ways you can choose
three distinct strings from A?
[4 marks]

The solution may vary depending on Σ. This solution is based on the assumption that
Σ has three elements. Say the Student UPI is abcd123, then Σ = {a, b, c, d, 1}.
To calculate |A|, we note that making a string of length k is the same as choosing k from
the set Σ = {a, b, c, d, 1}. Since we care about the order and we allow repetitions, there
are 3k many strings of length k.
That is, |A| = 30 + 31 + 32 + 33 + 34 + 35 = 364.
Now, our task is to choose three strings from 364. But the order in which we choose
them does not matter, and we don’t allow repetitions, there are 364
3
ways in which we
can do this.
In general, if |Σ| = n, then |A| = nk=0 nk
P

14. For every integer n ≥ 0, prove by induction that 24 is a factor of 52n − 1.


[4 marks]

P (n)=“24 is a factor of 52n − 1.”


Base case: Show that P (0) is true. Indeed,

52n − 1 = 50 − 1 = 0 = 24 · 0.

0 is a multiple of 24.
Inductive step: Assume that 52k − 1 is a multiple of 24 for integer k ≥ 0. Prove that
52(k+1) − 1 is also a multiple of 24.

Page 6 of ??
COMPSCI 120

By inductive hypothesis there is an integer h such that 52k − 1 = 24h. So

52k = 24h + 1

Now

52(k+1) − 1 = 52k+2 − 1 = 52 · 52k − 1 = 25 · 52k − 1 = 25(24h + 1) − 1 =

= 25 · 24h + 25 − 1 = 25 · 24h + 24 = 24(25h + 1)


25h + 1 is integer. Hence 52(k+1) − 1 is a multiple of 24.
By the principle of mathematical induction for every integer n ≥ 0 24 is a factor of
52n − 1.

15. Let G be a graph on n vertices (with no loops or multiple edges). Prove that if all vertices
in G have different degrees, then n = 1.

The proof is by contradiction. Suppose that all vertices in G have different degrees
but n ≥ 2. Since G has no multiple edges, the degree of every vertex is ≤ n − 1.
Since all degrees are different, there must be exactly one vertex of degree i for each
i{0, 1, . . . , n − 1}. We can therefore label the vertices as vi for i ∈ {0, 1, . . . , n − 1}, where
vi has degree i. Then vn−1 is adjacent to every other vertex. On the other hand, v0 is
not adjacent to any other vertex, so we have a contradiction. Therefore, n = 1.

[4 marks]

Page 7 of ??

You might also like