This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Solutions to Assignment 1 Anindya De Y4062 email: { anindya } @cse.iitk.ac.in February 5, 2008 Randomized Select Expected Number of Comparisons Solution: Let X be a random variable which denotes the number of comparisons made during any random experiment. Let h a 1 ,a 2 ,a 3 ,...,a j i be the elements of set S arranged in increasing order. Let X ij be a random variable which takes value 1 if and only if a i is compared to a j during the random experiment. Without loss of generality (and to avoid overcounting), we shall assume i &lt; j . It is trivial to see X = 1 i&lt;j n X ij . As X ij takes only values 0 and 1, hence we can say that Pr [ X ij = 1] = E [ X ij ]. Hence, using linearity of expectation, we can say E [ X ] = X 1 i&lt;j n Pr [ X ij = 1] (1) There are three possibilities for i and j . 1. 1 i &lt; j k In this case, note that X ij = 1 iff the first number to be randomly selected from { a i ,a i +1 ,...,a k 1 ,a k } is one of a i or a j . Since the numbers are selected uniformly randomly, the probability is 2 k i +1 . 2. k i &lt; j n In this case, note that X ij = 1 iff the first number to be randomly selected from { a k ,a k +1 ,...,a j 1 ,a j } is one of a i or a j . Since the numbers are selected uniformly randomly, the probability is 2 j k +1 . 3. 1 i &lt; k &lt; j n In this case, note that X ij = 1 iff the first number to be randomly selected from { a i ,a i +1 ,...,a j 1 ,a j } is one of a i or a j . Since the numbers are selected uniformly randomly, the probability is 2 j i +1 . Hence, Eqn 1 can be rewritten as E [ X ] = X 1 i&lt;j k Pr [ X ij = 1] + X k i&lt;j n Pr [ X ij = 1] + X 1 i&lt;k&lt;j n Pr [ X ij = 1] The first sum is X 1 i&lt;j k Pr [ X ij = 1] = X 1 i&lt;j k 2 k i + 1 = X 1 i&lt;k 2( k i ) k i + 1 &lt; 2 k The second sum is X k i&lt;j n Pr [ X ij = 1] = X k i&lt;j n 2 j k + 1 = X k&lt;j n 2( j k ) j k + 1 &lt; 2( n k ) 1 The third sum is X 1 i&lt;k&lt;j n Pr [ X ij = 1] = X 1 i&lt;k&lt;j n 2 j i + 1 = k 1 X i =1 n X j = k +1 2 j i + 1 To upper bound the inner sum, we see that n X j = k +1 2 j i + 1 &lt; Z n k 2 x i + 1 dx = 2ln n i + 1 k i + 1 Hence, we can conclude that X 1 i&lt;k&lt;j n Pr [ X ij = 1] &lt; k 1 X i =1 2ln n i + 1 k i + 1 = 2ln Q k 1 i =1 ( n i + 1) Q k 1 i =1 ( k i + 1) ! It is trivial to see that the denominator in the last term is Q k 1 i =1 ( k i + 1) = k !. Hence, we can say that 2ln Q k 1 i =1 ( n i + 1) Q k 1 i =1 ( k i + 1) ! &lt; 2ln Q k i =1 ( n i + 1) k ! ! = 2ln ( n k )! Q k i =1 ( n i + 1) k !( n k )! ! = 2ln n k &lt; 2 n ln2 The last inequality follows from the fact that ( n k ) &lt; 2 n (This follows from n k =0 ( n k ) = 2 n ). Hence adding all the three components of comparisons, we get E [ X ] = X 1 i&lt;j k Pr [ X ij = 1]+ X k i&lt;j n Pr [ X ij = 1]+ X 1 i&lt;k&lt;j n Pr [ X ij = 1] &lt; 2 k +2( n k )+2 n ln2 &lt; 3 . 39 n Hence, we have proven that the total number of comparisons in...
View
Full
Document
This note was uploaded on 11/24/2009 for the course CS CS648 taught by Professor Surenderbaswana during the Spring '08 term at University of Massachusetts Boston.
 Spring '08
 SurenderBaswana
 Algorithms

Click to edit the document details