02 - Divide & Conquer Partition & Selection (Solution)

02 - Divide & Conquer Partition & Selection (Solution)

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COMP 271: Design and Analysis of Algorithms Fall 2007 Below are the solutions of the problems of the tutorial. Question 1 : Let N ( n,i ) be the expected number of times Randomized-Select is called (first call and recursive calls) when finding the i -th smallest ele- ments in an array of n elements. Set up a recurrence equation for N ( n,i ). Solution: (Note: The question is asking about the number of times the function is called, not the number of comparisons as in the lecture notes.) Suppose we have chosen the k th smallest element in the first call of Randomized-Select: For i = k , expected number of calls to Randomized-Select is 1. For i > k , expected number of calls to Randomized-Select is: 1 + N ( n - k,i - k ) For i < k , expected number of calls to Randomized-Select is: 1 + N ( k - 1 ,i ) Therefore, the expected number of call to Randomized-Select is: 1 n ˆ 1 + i - 1 X k =1 (1 + N ( n - k,i - k )) + n X k = i +1 (1 + N ( k - 1 ,i )) ! 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

02 - Divide &amp; Conquer Partition &amp; Selection (Solution)

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online