non-text calculator allowed in this examina- tion

14
Non-text calculator allowed in this examina- tion School of Computer Science 06 30181 Mathematical Foundations of Computer Science — WITH ANSWERS — Main Summer Examinations 2019 Time allowed: 2:00 [Answer all questions] –1– Turn Over

Upload: others

Post on 14-Nov-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Non-text calculator allowed in this examina- tion

Non-text calculator allowed in this examina-

tion

School of Computer Science

06 30181

Mathematical Foundations of Computer Science

— WITH ANSWERS —

Main Summer Examinations 2019

Time allowed: 2:00

[Answer all questions]

– 1 – Turn Over

Page 2: Non-text calculator allowed in this examina- tion

Non-text calculator

Learning Outcomes

On successful completion of this module, the student should be able to:

(L1) solve mathematical problems in algebra and set theory;

(L2) apply mathematical techniques to solve a problem within a computer science setting;

(L3) explain the basics of automata theory, formal language theory, computability theory

and complexity theory;

(L4) describe and use the connection between finite automata and regular language;

(L5) explain non-computability and undecidability issues;

Part A

Question 1 [Linear Algebra, LO1]

(a) Consider the following parametric representations of a plane E and a line L in 3D:

E : X =

0

3

3

+ s ·

1

2

3

+ t ·

1

−1

1

L : Y =

1

3

−8

+ u ·

5

2

−3

(i) Find the point P where E and L intersect.

Answer: We equate X and Y to obtain three linear equations:

s + t = 1 + 5u

3 + 2s − t = 3 + 2u

3 + 3s + t = −8− 3u

which we solve by Gaussian elimination: 1 1 −5 1

2 −1 −2 0

3 1 3 −11

→ 1 1 −5 1

0 −3 8 −2

0 −2 18 −14

→ 1 1 −5 1

0 −3 8 −2

0 1 −9 7

→ 1 1 −5 1

0 1 −9 7

0 −3 8 −2

→ 1 1 −5 1

0 1 −9 7

0 0 −19 19

From which we see that u = −1. [3 marks]

This gives us the point of intersection

P =

1

3

−8

− 5

2

−3

=

−4

1

−5

[1 mark]

– 2 – Turn Over

Page 3: Non-text calculator allowed in this examina- tion

Non-text calculator

(ii) Show that L is orthogonal to E.

Answer: This will be the case if the direction vector of L is orthogonal to the

direction vectors of E. [1 mark]

We can test it by evaluating the inner product:⟨1

2

3

,

5

2

−3

⟩= 5+4−9 = 0 and

⟨ 1

−1

1

,

5

2

−3

⟩= 5−2−3 = 0

[1 mark]

(iii) Use the previous item to describe E in normal form.

Answer: Since we have a normal in the direction vector of L, we can use the

representation 〈X, ~n〉 = 〈P, ~n〉 where P is any point on the plane. [1 mark]

We get

〈X, ~n〉 = 5x1 + 2x2 − 3x3 and 〈P, ~n〉 = −20 + 2 + 15 = −3

[1 mark]

(b) Find the inverse of the following matrix over GF(2): 1 1 1

1 0 1

1 1 0

Answer: 1 1 1 1 0 0

1 0 1 0 1 0

1 1 0 0 0 1

→ 1 1 1 1 0 0

0 1 0 1 1 0

0 0 1 1 0 1

→ 1 1 0 0 0 1

0 1 0 1 1 0

0 0 1 1 0 1

→ 1 0 0 1 1 1

0 1 0 1 1 0

0 0 1 1 0 1

[6 marks]

(c) Let V be an algebra of vectors and let B = {~v1, . . . , ~vn} ⊆ V be a collection of

elements of V .

(i) When do we say that B generates V ?

– 3 – Turn Over

Page 4: Non-text calculator allowed in this examina- tion

Non-text calculator

Answer: B generates V if every vector ~w in V is a linear combination of

the vectors in B. More explicitly, if there are scalars a1, . . . , an such that

~w = a1 · ~v1 + . . .+ an · ~vn. [2 marks]

One mark reserved for a clear and concise answer. [1 mark]

(ii) Assuming B generates V , why are we interested in the elements of B being

“linearly independent” of each other?

Answer: To say that the elements of B are linearly independent of each other

means that there is no redundancy in B: The null vector does not belong to B

(as it generates nothing) [1 mark]

and no element of B is a linear combination of the others (as it would then not

be needed). [1 mark]

One mark reserved for a clear and concise answer. [1 mark]

– 4 – Turn Over

Page 5: Non-text calculator allowed in this examina- tion

Non-text calculator

Question 2 [Set Theory, LO1 & LO2]

(a) (i) List the elements of the set {(x, y) ∈ N× N | x + 2y = 10}.

Answer:

{(x, y) ∈ N× N | x + 2y = 10} = {(0, 5), (2, 4), (4, 3), (6, 2), (8, 1), (10, 0)}

[1 mark]

(ii) Describe the cardinality of each of the following sets, giving brief justifications:

• The set of numbers that can be stored as a float in Java.

Answer: This is a finite set, as every float is encoded as a 32-bit pattern,

and there are only 232 many of those. [2 marks]

• The set of valid Java programs.

Answer: This is a countably infinite set, as every Java program may

be viewed as a string over the (finite) Unicode alphabet. It was shown

in the lectures that the set of strings over a finite alphabet is countable.

[2 marks]

• The set R of real numbers.

Answer: This is an uncountable set as was shown in the lectures. The

proof is by contradiction: Any attempt to list all real numbers allows us to

exhibit some number that cannot be in the listing. [3 marks]

(b) Consider the following binary relation ≈ on Z× Z:

(a, b) ≈ (c, d)def⇐⇒ a2 + b2 = c2 + d2

(i) Check that ≈ is an equivalence relation.

Answer: Reflexivity: (a, b) ≈ (a, b) because a2 + b2 = a2 + b2. [1 mark]

Symmetry: If (a, b) ≈ (c, d), then by definition this means a2 + b2 = c2 + d2.

Equality is symmetric, so c2 + d2 = a2 + b2 is also true, and by definition this

means (c, d) ≈ (a, b). [1 mark]

Transitivity: Assuming (a, b) ≈ (c, d) and (c, d) ≈ (e, f ), we have a2 + b2 =

c2 + d2 and c2 + d2 = e2 + f 2 by definition. Since equality is transitive,

a2 + b2 = e2 + f 2 follows which implies (a, b) ≈ (e, f ). [1 mark]

(ii) By interpreting the elements of Z×Z as the coordinates of points in the plane,

sketch a diagram which illustrates the equivalence classes of ≈.

– 5 – Turn Over

Page 6: Non-text calculator allowed in this examina- tion

Non-text calculator

Answer:

x

y

1 2 3 4 5 6

1

2

3

-1

-2

-3

-1-2-3-4-5-6

The equivalence classes consist of points that lie on a circle around the origin.

[2 marks]

(iii) What is the minimum number of elements in each equivalence class?

Answer: The smallest equivalence class is that of (0, 0) which contains only

one element. All other equivalence classes contain at least four elements.

[1 mark]

(c) (i) Consider the function r :R → Z which rounds a real number to the nearest

integer. Is it injective, surjective, bijective? Give brief justifications for your

answers.

Answer: It is not injective because, for example, 0.2 and 0.1 both round to

zero. [1 mark]

It is surjective because every integer rounds to itself. [1 mark]

Since the function is not injective it can’t be bijective. [1 mark]

(ii) Compare r with the built-in Java method

int round(float f)

Answer: Any three of the following will give full (i.e., three) marks: [3 marks]

• The domain of round is not R since float contains only finitely many

rational numbers.

• The co-domain of round is not Z since int contains only finitely many

integers.

• The function round can not be defined for all elements of float since

there are floating point numbers that are much bigger than any int.

• The function round can no longer be surjective since there are values in

int which have no float nearby.

– 6 – Turn Over

Page 7: Non-text calculator allowed in this examina- tion

Non-text calculator

Part B

Question 3 [Languages and Automata]

(a) (i) Describe two kinds of problem for which you would specify a language (e.g. by

means of a regular expression) when using a tool to solve them. [3 marks]

Answer: Matching problem: saying whether a given word belongs to the lan-

guage. Searching problem: within a file, finding all occurrences of words be-

longing to the language. LOs 3, covered in lectures

(ii) For the alphabet Σ = {a, b, c}, give a regular expression for those words in

which a and b appear at least once. [4 marks]

Answer:

((a|b|c)∗a(a|b|c)∗b(a|b|c)∗)|((a|b|c)∗b(a|b|c)∗a(a|b|c)∗)

LO 3, creative

(b) For the alphabet Σ = {a, b}, obtain a deterministic finite automaton for (ba)∗ |bb(ab)∗, by first writing down automata for (ba)∗ and bb(ab)∗, then combining,

then determinizing. [4 marks]

Answer:

For (ba)∗:

For bb(ab)∗:

Combining:– 7 – Turn Over

Page 8: Non-text calculator allowed in this examina- tion

Non-text calculator

Determinizing:

LOs 3,4, the first part is somewhat creative

(c) (i) What does it mean for a grammar to be ambiguous? [2 marks]

Answer:

Some word has more than one derivation tree.

LOs 3, covered in lectures

(ii) Show that this grammar, for the alphabet Σ = {a, b}, is ambiguous.

M ::= abMb | ε | abb

[3 marks]

Answer:

The word abb has the following two derivation trees:

– 8 – Turn Over

Page 9: Non-text calculator allowed in this examina- tion

Non-text calculator

LO 3, creative

(iii) Show that there is no regular expression that generates this language. [4 marks]

Answer:

The language recognized by this grammar is {(ab)nbn | n ∈ N}. If it is regular,

then there is a DFA (X, p, δ,Acc) that recognizes it. Let xn be the state that

we arrive at when we start from p and read (ab)n. We shall prove these states

are all distinct, so there are infinitely many states, a contradiction. For m < n,

we want to show xm 6= xn. If we start at xm and read bm we reach an accepting

state, but if we start at xn and read bm we reach a rejecting state; hence

xm 6= xn.

LO 3,4, creative

– 9 – Turn Over

Page 10: Non-text calculator allowed in this examina- tion

Non-text calculator

Question 4 [Computability and Complexity]

(a) (i) Andy is implementing a programming language for his final year project. Cer-

tain programs cause a VeryBadException. He tells his supervisor, Brenda, that

he intends to detect all such programs. She replies that this problem is unde-

cidable. What does this mean? [3 marks]

Answer:

That there is no Turing machine that, when run with the code of a program

on the tape, will return True if the program causes a VeryBadException and

False otherwise.

LOs 3,5, covered in lectures but the setting is somewhat different

(ii) What are the implications of Church’s thesis for Brenda’s comment? [2 marks]

Answer:

Church’s thesis says that any decision problem that can be solved algorithmically

can be solved by a Turing machine. It implies that, if Brenda’s comment

is correct, then there is no algorithmic procedure that can detect whether a

program raises a VeryBadException.

LOs 3,5, covered in lectures but the setting is somewhat different

(b) Here is a Turing machine with tape alphabet {a, b, }.

5⇒ Right 2

Read

6

Right

9 Left

43

Read

29 Stop

7

Stop

12 Write a

a

b

b

a

At the start of execution, the head is to the left of a block of n > 1 letters that are

all a or b, on an otherwise blank tape.

– 10 – Turn Over

Page 11: Non-text calculator allowed in this examina- tion

Non-text calculator

(i) When the input block is ab, trace the execution. (The number of steps, in-

cluding Stop, is less than 10.)

[3 marks]

Answer:Contents and position State Instruction

˙ab 5 Right

ab 2 Read a

ab 6 Right

ab 43 Read b

ab 12 Write a

aa 6 Right

aa˙ 43 Read

aa˙ 7 Stop

LO 3, not creative

(ii) For a general input block, what is the contents of the tape and the head position

when execution stops? [3 marks]

Answer:

If the leftmost character of the input block is a, then finally the tape contains

the same block, in the same position, except that every occurrence of b is

replaced by a, and the head is to the right of the block.

If the leftmost character of the input block is b, then finally the tape contains

the same block, in the same position, and the head is to its left.

LO 3, somewhat creative

(iii) Give the worst case number of steps (including Stop) and show that it is O(n).

[3 marks]

Answer:

In the worst case, the input block is abn−1 and the number of steps is 2 + 3(n−1) + 3 = 3n + 2. This is linear because 3n+2

n= 3 + 2

n6 5.

LO 3, creative

(c) (i) What does it mean for a search problem to be anNP search problem? [3 marks]

– 11 – Turn Over

Page 12: Non-text calculator allowed in this examina- tion

Non-text calculator

Answer:

The length of a candidate solution is polynomial in the size of the input, and

the time taken to check whether it’s an actual solution is polynomial in the size

of the input.

LO 3, covered in lectures

(ii) Consider the following problem. Given a finite list of numbers with no repe-

tition, select at least half of these numbers that appear in increasing order, if

possible. For example, given [3, 8, 4, 5, 2, 7, 9], acceptable solutions would be

[3, 4, 5, 7] or [4, 5, 7, 9] or [3, 4, 5, 7, 9]. But given [3, 8, 9, 4, 5, 2, 1] you would

say “Impossible”. Explain why this is an NP search problem. [3 marks]

Answer:

An input is a list of numbers written out in (e.g.) decimal digits. A candidate

solution highlights some of these, so its length is 6 the length n of the input,

i.e. polynomial in n. Each number in the list of candidates has 6 n digits,

so comparing two of them takes O(n) steps. There are 6 n numbers in the

candidate, so comparing all consecutive pairs takes O(n2) steps, i.e. polynomial

in n.

LO 3, creative

– 12 – End of Paper

Page 13: Non-text calculator allowed in this examina- tion

This page intentionally left blank.

– 13 –

Page 14: Non-text calculator allowed in this examina- tion

Do not complete the attendance slip, fill in the front of the answer book or turn over the question paper until you are told to do so

Important Reminders

• Coats/outwear should be placed in the designated area.

• Unauthorised materials (e.g. notes or Tippex) must be placed in the

designated area.

• Check that you do not have any unauthorised materials with you (e.g. in your pockets, pencil case).

• Mobile phones and smart watches must be switched off and placed in the designated area or under your desk. They must not be left on your person or in your pockets.

• You are not permitted to use a mobile phone as a clock. If you have difficulty seeing a clock, please alert an Invigilator.

• You are not permitted to have writing on your hand, arm or other body part.

• Check that you do not have writing on your hand, arm or other body part – if you do, you must inform an Invigilator immediately

• Alert an Invigilator immediately if you find any unauthorised item upon you during the examination.

Any students found with non-permitted items upon their person during the examination, or who fail to comply with Examination rules may be subject to Student Conduct procedures.

Mathematical Foundations of Computer Science

— WITH ANSWERS —