{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

# 02 - Divide & Conquer Partition & Selection (Solution)

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

The Hong Kong University of Science & Technology COMP 271: Design and Analysis of Algorithms Fall 2007 Tutorial 2 D&C: Partition & Selection (Solution) 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 )) !

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}