Sunteți pe pagina 1din 2

CS648 : Randomized Algorithms Semester I, 2013-14, CSE, IIT Kanpur

Theoretical Assignment - 1 (due on 30 August: 5PM)


Note: Be very rigorous in providing any mathematical detail in support of your arguments. Also mention any Lemma/Theorem you use. 1. Randomized quick select Let S be a set of n real numbers. Consider the randomized algorithm Rand-QSelect (k, S ) described below that nds the k th smallest element from the set S . Select a pivot element x uniformly randomly from set S . Find its rank in the set S (by comparing x with every other element of set S ). Let r be the rank of x. If r = k , we report x as the output. Otherwise we proceed recursively as follows: If r > k , then Rand-QSelect (k, S<x ) Else Rand-QSelect (k r, S>x ) Where S<x and S>x are the sets consisting of all those elements that are respectively smaller and greater than the element x. Observe that the running time of the above algorithm is dominated by the number of comparisons performed. Therefore, in order to get a bound on the expected running time of the algorithm, our aim is essentially to nd out the expected number of comparisons performed in Rand-QSelect (k, S ). Prove the following statements. (a) The expected number of comparisons is at most 4n (highly motivated students, without any incentive of extra marks, should strive to prove an upper bound of 3.5n). (b) There are elements in set S which will be compared expected (log n) times during the algorithm. Can you characterize these elements (this part of the problem is not to be submitted) ? 2. Two-dimensional Pattern Matching (a) First we shall discuss a dierent nger printing technique to solve one-dimensional pattern matching problem. The idea is to map any bit string s into a 2 2 matrix M (s), as follows. i. ii. iii. iv.
0 For the empty string , M ( ) = 1 01 1 0 M (0) = 1 1 1 M (1) = 1 01 For non-empty strings x and y , M (xy ) = M (x) M (y ).

Show that this ngerprint function has the following properties. i. M (x) is well dened for all x {0, 1} . ii. M (x) = M (y ) x = y . iii. For x {0, 1}n , the entries in M (x) are bounded by Fibonacci number Fn . By considering the matrices M (x) modulo a suitable prime p, show how you would perform ecient randomized pattern matching in 1-dimension. Explain how you would implement this as a real-time algorithm.

(b) Consider the two-dimensional version of the pattern matching problem. The text is an n n matrix X , and the pattern is an m m matrix Y . A pattern match occurs if Y appears as a (contiguous) sub-matrix of X . Get inspired from the randomized algorithm for part (a) above to design a randomized algorithm for this 2-dimensional pattern matching. The running time should be O(n2 + m2 ) and the error probability should be inverse polynomial in terms of n and m. The hint is: How to convert 2-dimensional pattern matching to 1-dimensional pattern matching. This hint will be expanded further on Friday (23 August). Till then keep pondering over it.

S-ar putea să vă placă și