0% found this document useful (0 votes)
11 views

AA Resit 2020 Answers

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)
11 views

AA Resit 2020 Answers

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/ 5

UNIVERSITY OF BRISTOL

August/September 2020

Faculty of Engineering

Resit & Supplementary Examination for the Degrees


of
Bachelor of Science
Master of Engineering

COMS31900(R)
Advanced Algorithms

TIME ALLOWED:
2 Hours

This paper contains 5 questions worth a maximum of 100 marks.


All answers will be used for assessment.

PLEASE WRITE YOUR 7 DIGIT STUDENT NUMBER (NOT CANDIDATE NUMBER)


ON THE ANSWER BOOKLET. YOUR STUDENT NUMBER CAN BE FOUND ON
YOUR UCARD.

All questions will be used for assessment.


Calculators must have the Faculty of Engineering seal of approval.

TURN OVER ONLY WHEN TOLD TO START WRITING.


Answers to multiple choice questions should be written in the answer booklet along with all the other
answers you give.
1. (a) (6 points) Suppose that we use a Bloom filter with a table of size n = 100 and two completely
random hash functions chosen from the set of all functions mapping the universe U to the domain
[n]. Suppose further that we have inserted exactly 30 distinct elements into the Bloom filter.
We now execute Member(k), for some element k ∈ U that has not previously been inserted into
the Bloom filter. Let p be the probability that Member(k) returns true. Observe that p depends
on the number of collisions in the Bloom filter. What is the precise range of p?
1 9
A. 2500 ≤ p ≤ 25
1 9
B. 2500 ≤ p ≤ 100
4 9
C. 625 ≤ p ≤ 100
4 9
D. 625 ≤ p ≤ 25
E. none of the above

Solution: First, observe that the 30 elements occupy at most 60 cells in the table, and it is
possible that they occupy indeed exactly 60 cells. Then, the probability that two randomly
chosen positions are contained in these 60 cells is
 2  2
60 3 9
= = .
100 5 25

Next, it may have happened that all 30 elements were mapped to the first two cells of the
Bloom filter. The probability of a false positive would then be
 2
2 1
= .
100 2500

Answer A is therefore correct.

(b) (6 points) Consider a hash table of size m. Suppose that we selected a completely random hash
function h from the set of all functions mapping the universe U to the set [m]. Suppose that we
inserted m log m items into the hash table using the hash function h. What is the expected number
of collisions (recall that a collision is a pair of inserted items that are mapped to the same location)?
A. Θ(1)
B. Θ(log m)
C. Θ(log2 m)
D. Θ(m)
E. Θ(m log m)
F. Θ(m log2 m)
G. none of the above

Solution: Answer F: Θ(m log2 m)

2. (a) (6 points) Give one property of Bloom filters that makes it superior to Cuckoo hashing.

Solution: Bloom filters run in O(1) worst-case time. The insert operation in Cuckoo hashing
only has amortized expected runtime O(1).

(b) (6 points) Give one property of Cuckoo hashing that makes it superior to Bloom filters.

Page 2
Solution: Cuckoo hashing supports deletions while Bloom filters do not support deletions.

(c) (6 points) Let H be a family of weakly-universal hash functions h with h : {0, . . . , u − 1} → {0, 1}.
We now construct a family of hash functions G with g : {0, . . . , u − 1} → {0, 1, 2, 3} as follows: For
every pair of hash functions (h1 , h2 ) ∈ H2 , we include the function h1 (x) + 2 · h2 (x) into G. Prove
that G is weakly universal.

Solution: We have g(x) = g(y) ⇔ h1 (x) = h1 (y) and h2 (x) = h2 (y). Since the choice of h1
and h2 is independent, we have that the probability of collision is at most 21 · 12 = 14 . The set
G is therefore weakly universal.

(d) (6 points) Let H be a family of hash functions h with h : {0, . . . , u − 1} → {0, . . . , k − 1}. Suppose
that |H| = 1, i.e., H contains only a single hash function. Give an example for H that shows that
if k ≥ u then H is weakly universal. Further, prove that H is not weakly universal if k < u.

Solution: If k ≥ u then the set that contains an arbitrary injection is weakly-universal. If


k < u, then there are necessarily two items that are always mapped to the same location.
The family that contains this function is therefore not weakly universal, since the collision
probability for these two elements is then 1.

(e) (6 points) Suppose that we are given a sequence of n instructions. What does it mean if each
of these instructions has amortized expected runtime O(f (n))? Furthermore, illustrate what this
means in the context of Cuckoo hashing.

Solution:
P Let ti be the expected runtime of instruction i. Then we are guaranteed that
t
i i = n · O(f (n)). The insert operation in Cuckoo hashing has amortized expected runtime
of O(1). This means that in a sequence of n insert operations, some inserts may have an
expected runtime ω(1), but in average, the n inserts have an expected runtime of O(1).

(f) (5 points) Let U be a universe of size u. What is the worst-case runtime of any operation that a
van Emde Boas tree that is built on U supports? No justification needed.

Solution: O(log log u)

(g) (5 points) What are the space requirements of the 2D orthogonal range searching data structure
discussed in the lectures when it stores n distinct points? Justify your answer very briefly.

Solution: It requires space O(n log n). All nodes in any level i of the binary tree store a
partition of the n points. Since there are at most log n levels, the space required by this data
structure is O(n log n).

3. (6 points) Construct the Cartesian tree for the input 9, 3, 7, 1, 8, 12, 10, 20, 15, 18, 5.

Page 3
1

3 5

9 7 8

10

12 15

20 18
Solution:

4. (a) (6 points) Give the definition of an FPTAS for an optimisation problem. You may give only the
minimisation version.

Solution: An FPTAS is a family of algorithms such that for any constant  > 0 there is a
polynomial time (in both n and 1/) algorithm A such that A is a (1 + )-approximation
algorithm for P .

(b) (6 points) Give the definition of an APTAS for an optimisation problem. You may give only the
minimisation version.

Solution: An asymptotic polynomial approximation scheme (APTAS) for problem P is a fam-


ily of algorithms. There is a constant c > 0 such that for any constant  > 0, A runs in
polynomial time (in n) and outputs a solutions s with OP T ≤ s ≤ (1 + )Opt + c.

(c) (6 points) Give two differences between an FPTAS and an APTAS.

Solution: Differences: An FPTAS has time complexity which is polynomial in both n and 1/
and an APTAS has +c in the upper bound for the approximation .

5. Consider the optimisation problem SUBSET SUM: Given a set S = {s1 , . . . , sm } of m integers and an
integer t, find the size of the largest subset of S which is no larger than t. Recall that the size of a set
is the sum of its elements. Now look at the following partial algorithm for computing the exact answer:
1: L0 = {0}
2: for i ← 1 to m do
3: Compute (Li−1 + si ) from
4: Compute Li = ∪ (Li−1 + si )
5: end for
6: Output

(a) (6 points) What should be in place of the two blank spaces on lines 3 and 4?

Solution: See below.

(b) (6 points) What should be in place of the blank space on line 6?

Solution:
L0 = {0}
for i ← 1 to m do

Page 4
Compute (Li−1 + si ) from Li−1
Compute Li = Li−1 ∪ (Li−1 + si )
end for
Output the largest number in Lm

(c) (6 points) What is the running time of this algorithm? You should give the strongest worst case
asymptotic running time possible.

Solution: O(mt)

(d) (6 points) Does this algorithm run in polynomial time? Give a brief justification of your answer.

Solution: No because t could be as big as 2n where n is the length of the input.

Page 5

You might also like