solution1 - Solutions to Assignment 1 Anindya De Y4062...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Solutions to Assignment 1 Anindya De Y4062 e-mail: { 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 over-counting), we shall assume i < j . It is trivial to see X = 1 i<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<j n Pr [ X ij = 1] (1) There are three possibilities for i and j . 1. 1 i < 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 < 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 < k < 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<j k Pr [ X ij = 1] + X k i<j n Pr [ X ij = 1] + X 1 i<k<j n Pr [ X ij = 1] The first sum is X 1 i<j k Pr [ X ij = 1] = X 1 i<j k 2 k - i + 1 = X 1 i<k 2( k - i ) k - i + 1 < 2 k The second sum is X k i<j n Pr [ X ij = 1] = X k i<j n 2 j - k + 1 = X k<j n 2( j - k ) j - k + 1 < 2( n - k ) 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The third sum is X 1 i<k<j n Pr [ X ij = 1] = X 1 i<k<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 < Z n k 2 x - i + 1 dx = 2 ln n - i + 1 k - i + 1 Hence, we can conclude that X 1 i<k<j n Pr [ X ij = 1] < k - 1 X i =1 2 ln n - i + 1 k - i + 1 = 2 ln ˆ 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 2 ln ˆ Q k - 1 i =1 ( n - i + 1) Q k - 1 i =1 ( k - i + 1) ! < 2 ln ˆ Q k i =1 ( n - i + 1) k ! ! = 2 ln ˆ ( n - k )! Q k i =1 ( n - i + 1) k !( n - k )! ! = 2 ln n k < 2 n ln 2 The last inequality follows from the fact that ( n k ) < 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<j k Pr [ X ij = 1]+ X k i<j n Pr [ X ij = 1]+ X 1 i<k<j n Pr [ X ij = 1] < 2 k +2( n - k )+2 n ln 2 < 3 . 39 n Hence, we have proven that the total number of comparisons in Rand - Select ( n, k ) is less than 3 . 5 n . Elements which are compared Θ(log n ) times Without loss of generality, we will try to find the condition for element i such that i < k . The comparisons that element i makes with another element j in the array can be of the following three types 1 j < i - As proven earlier, the probability of such a comparison is 2 k - j +1 i < j k
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern