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

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

View Full Document Right Arrow Icon
Order Statistics Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill
Background image of page 1

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

View Full DocumentRight Arrow Icon
Order Statistic
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
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 .
Background image of page 7

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

View Full DocumentRight Arrow Icon
Total no. of comparisons , C 3 n /2 . » For odd
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online