06-Order-Statistics

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

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

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

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

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

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

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

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

This note was uploaded on 04/29/2011 for the course IT 201 taught by Professor K.v.arya during the Spring '11 term at IIT Kanpur.

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