AA Resit 2020 Answers
AA Resit 2020 Answers
August/September 2020
Faculty of Engineering
COMS31900(R)
Advanced Algorithms
TIME ALLOWED:
2 Hours
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
(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
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.
(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.
(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: 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:
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.
Page 5