Sie sind auf Seite 1von 2

CS601 Algorithms and Complexity 2020 Sem 1

Assignment 1
Total Marks: 100 Deadline: September 21, Monday 9 AM

Note: The assignments can be done in groups of two students. There should not be any discussions across
different groups. If you are stuck at a question, you can ask for some hints to be posted. Please submit your
solutions on Moodle. If the solutions are hand-written, please make sure your writing is very clear, and it
is clearly readable from the scan/image. Keep your answers succinct and to the point. You need to give
arguments for correctness of your strategy/algorithm whenever it is not obvious (to any fellow student). You
don’t need to necessarily follow the given hints.

Que 1 [10 marks] Lower bound for sorting. Suppose you are designing a comparison based sorting
algorithm. That is, you can only access the given array A by a comparison query, where you can ask for
a comparison between any two elements of the array. You are supposed to output the sorted sequence of
indices (i1 , i2 , . . . , in ) where A[i1 ] ≥ A[i2 ] ≥ · · · ≥ A[in ]. We want to show a lower bound on number of
comparisons required for any such sorting algorithm. Let us think information theoretically.

• How many bits of information do you get from each comparison?


• The output of the algorithm is a permutation of (1, 2, 3, . . . , n) out of all possible n! permutations.
What is the minimum number of bits you need to represent the output? Note that you can also
represent a permutation by a number between 1 and n!.
• Using the two points above, what is the lower bound on number of comparisons required.

Que 2 [10+0 marks] Pool Testing for Covid. As we had discussed, to reduce the number of tests in a
low-prevalence area, one idea is to do pool testing. Here, you mix samples from multiple people to create a
pool and test that pool. A pool is positive if and only if at least one of the persons in that group is positive.
Suppose you have a set of n persons. Given the prevalence rate, you know that almost certainly there are
at most two persons out of n who are positive.

1. Your task is to design a one-round pool testing strategy to find out the persons who are positive (one
round means you have to test all the pools simultaneously, you cannot wait for the result from one
pool before testing another pool). Due to various logistics
√ reasons, you can mix a person’s sample into
at most three pools. Your strategy should do only O( n) tests.
2. This part has no marks, but should be interesting to solve. Suppose you are only allowed to mix a
person’s sample into at most two pools. Can you design a strategy with only O(n2/3 ) tests? May be
first you can relax the one-round condition and solve it. Ultimately we would like a one round solution.
Hint: there are graph constructions where the graph has m edges and has only O(m2/3 ) vertices,
moreover the graph has no cycles of length 4 or smaller. Such a construction can be found at https:
//core.ac.uk/download/pdf/82145602.pdf .

Que 3 [10 marks]. You are given an array A of n integers, say a1 , a2 , . . . , an . We are interested in the
degree n polynomial P (x) whose roots are these given n numbers, that is,

P (x) = (x − a1 )(x − a2 ) · · · (x − an ).

Note that here the coefficient of xn is 1, the coefficient of xn−1 is −(a1 + a2 + · · · + an ). In general, the
coefficient of xn−k is X
(−1)k ai1 ai2 · · · aik ,
1≤i1 <i2 <···<ik ≤n

1
where the sum is over all size k subsets of {1, 2, . . . , n}.
Design an algorithm that takes the array A and a number k and outputs the coefficient of xn−k in P (x).
The time complexity of the algorithm should ideally be O(kn). Zero marks if the time complexity is O(nk ).
Hint: Try going to a subproblem, what if the solution is already given for the length n − 1 subarray? Is
that good enough or do you need a bit stronger subproblem?

Que 4 [10 marks] Median of two sorted arrays. You are given two sorted arrays with all distinct
integer entries, where each array has length n. Find the median of the union of these two arrays by accessing
only O(log n) entries in the arrays.

Que 5 [10+10 marks] (Majority Fingerprint). You are given a collection of n fingerprints. You are
also told that at least half of these (n/2) are identical to each other. You are only given access to an equality
test, which takes two fingerprints and tells whether they are identical or not. Using this equality test, can
you find out the one with at least n/2 copies? Can you do this in O(n log n) tests? Can you improve it to
O(n) tests?
Hint: Divide and conquer

Que 6 [10 marks] (Profit in the stock market). Suppose you are given prices for a particular stock
for next n days, say p1 , p2 , , pn . You want to buy one stock on one of the upcoming days and sell it on a
later day. Both buying and selling should be done within the next n days. You want to find out the buying
day and the selling day which will maximize your profit. Your run-time should O(n).
Hint: suppose the problem is already solved for first n − 1 days, can you use it to solve it for n days?

Que 7 [15 marks] Convex Minimization. One of the characterizations of a differentiable convex func-
tion f (x) says that its derivative f 0 (x) is a non-decreasing function. That is, for any x1 > x2 , we have
f 0 (x1 ) ≥ f 0 (x2 ). Suppose that f (x) is minimized at x = x0 . Then what is f 0 (x0 ) (zero marks for getting
this)? What can you say about f 0 (x) in the two regions x < x0 and x > x0 ?
You are given a convex function f (x), but not in an explicit closed form (that means you cannot compute
an expression for f 0 (x)). Instead, you only have a query access - you can query the value of f (x) for any
integer x. We want to find an integer m which minimizes the value of f , i.e., for any integer m0 6= m, we
have f (m) ≤ f (m0 ). Can you find m by querying f (x) at only O(log m) points? If it helps you can imagine
how does the function x2 look like on integers.
Note that we are asking for the number of queries to be output-dependent and not input-dependent.
Such a scenario is very common in optimization, where your cost of computation depends on the precision
up to which you are outputting your answer.
Hint: it is a search with an unknown range.

Que 8 [15 marks]. Consider two polynomials Pa (x) = a0 + a1 x and Pb (x) = b0 + b1 x + b2 x2 , given as a
list of coefficients, where the coefficients are of at most ` bits. We want to compute all the coefficients in the
product polynomial Pa × Pb , which are

a0 b0 , a1 b0 + a0 b1 , a1 b1 + a0 b2 , a1 b2 .

When you add two `-bit numbers, or when you when you multiply an `-bit number with a constant (e.g,
3/2), it takes O(`) time. While when you multiply two `-bit numbers, it takes a significantly larger time,
say M (`), which is at most `2 . Can you compute the above four coefficients using in time 4M (`) + O(`).
Something which might be useful is M (` + 1) = M (`) + O(`) (follows from M (`) ≤ `2 ).

Das könnte Ihnen auch gefallen