{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ostat

# ostat - Order Statistics Many of the slides are from Prof...

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

Order Statistics Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill

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

View Full Document
Order Statistic
Selection Problem Selection problem : » Input: A set A of n distinct numbers and a number i , with 1 i n . » Output: the element x A that is larger than exactly i – 1 other elements of A . Can be solved in O ( n lg n ) time. How? We will study faster linear-time algorithms . » For the special cases when i = 1 and i = n . » For the general problem.

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

View Full Document
Minimum (Maximum) Minimum ( A ) 1. min A [1] 2. for i 2 to length [ A ] 3. do if min > A [ i ] 4. then min A [ i ] 5. return min Maximum can be determined similarly. T ( n ) = Θ ( n ). No. of comparisons: n – 1. Can we do better? Why not? Minimum( A ) has worst-case optimal # of comparisons.
Problem Average for random input: How many times do we expect line 4 to be executed? » X = RV for # of executions of line 4. » X i = Indicator RV for the event that line 4 is executed on the i th iteration. » X = Σ i =2. . n X i » E[X i ] = 1/ i . How? » Hence, E[X] = ln( n ) – 1 = Θ (lg n ). Minimum ( A ) 1. min A [1] 2. for i 2 to length [ A ] 3. do if min > A [ i ] 4. then min A [ i ] 5. return min

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

View Full Document
Simultaneous Minimum and Maximum Some applications need to determine both the maximum and minimum of a set of elements. » Example: Graphics program trying to fit a set of points onto a rectangular display. Independent determination of maximum and minimum requires 2 n – 2 comparisons. Can we reduce this number? » Yes.
Simultaneous Minimum and Maximum Maintain minimum and maximum elements seen so far. Process elements in pairs. » Compare the smaller to the current minimum and the larger to the current maximum. » Update current minimum and maximum based on the outcomes. No. of comparisons per pair = 3. How? No. of pairs n /2 . » For odd n : initialize min and max to A [1]. Pair the remaining elements. So, no. of pairs = n /2 . » For even n : initialize min to the smaller of the first pair and max to the larger. So, remaining no. of pairs = ( n – 2)/2 < n /2 .

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

View Full Document
Total no. of comparisons , C 3 n /2 . » For odd
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 26

ostat - Order Statistics Many of the slides are from Prof...

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

View Full Document
Ask a homework question - tutors are online