06-Order-Statistics

# 06-Order-Statistics - Algorithms LECTURE 6 Order Statistics...

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

Algorithms L6.1 Professor Ashok Subramanian L ECTURE 6 Order Statistics Randomized divide and conquer Analysis of expected time Worst-case linear-time order statistics Analysis Algorithms

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

View Full Document
Algorithms L6.2 Order statistics Select the i th smallest of n elements (the element with rank i ). i = 1 : minimum ; i = n : maximum ; i = ( n +1)/2 or ( n +1)/2 : median . Naive algorithm : Sort and index i th element. Worst-case running time = Θ ( n lg n ) + Θ (1) = Θ ( n lg n ) , using merge sort or heapsort ( not quicksort).
Algorithms L6.3 Randomized divide-and- conquer algorithm R AND -S ELECT ( A , p, q, i ) i th smallest of A [ p . . q ] if p = q then return A [ p ] r R AND -P ARTITION ( A , p, q ) k r p + 1 k = rank( A [ r ]) if i = k then return A [ r ] if i < k then return R AND -S ELECT ( A , p, r – 1 , i ) else return R AND -S ELECT ( A , r + 1 , q, i – k ) A [ r ] A [ r ] r p q k

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

View Full Document
Algorithms L6.4 Example pivot i = 7 6 10 13 5 8 3 2 11 k = 4 Select the 7 – 4 = 3 rd smallest recursively. Select the i = 7 th smallest: 2 5 3 6 8 13 10 11 Partition:
Algorithms L6.5 Intuition for analysis Lucky: 1 0 1 log 9 / 10 = = n n C ASE 3 T ( n ) = T (9 n /10) + Θ ( n ) = Θ ( n ) Unlucky: T ( n ) = T ( n – 1) + Θ ( n ) = Θ ( n ) arithmetic series Worse than sorting! (All our analyses today assume that all elements are distinct.)

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

View Full Document
Algorithms L6.6 Analysis of expected time Let T ( n ) = the random variable for the running time of R AND -S ELECT on an input of size n , assuming random numbers are independent. For k = 0, 1, …, n –1 , define the indicator random variable X = 1 if P ARTITION generates a k : n k –1 split, 0 otherwise. The analysis follows that of randomized quicksort, but it’s a little different.
Algorithms L6.7 Analysis (continued) T ( n ) = T (max{0, n –1}) + Θ ( n ) if 0 : n –1 split, T (max{1, n –2}) + Θ ( n ) if 1 : n –2 split, L T (max{ n –1, 0}) + Θ ( n ) if n –1 : 0 split, ( 29 - = Θ + - - = 1 0 ) ( }) 1 , (max{ n k k n k n k T X .

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 ]}

### Page1 / 30

06-Order-Statistics - Algorithms LECTURE 6 Order Statistics...

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

View Full Document
Ask a homework question - tutors are online