Order Statistics Def: Let A be an ordered set containing n elements. The i-th order statistic is the i-th smallest element. Minimum: 1st order statistic.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Order Statistics. order - 2 Lin / Devi Comp 122 Order Statistic i th order statistic: i th smallest element of a set of n elements.
Advertisements

CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
1 More Sorting; Searching Dan Barrish-Flood. 2 Bucket Sort Put keys into n buckets, then sort each bucket, then concatenate. If keys are uniformly distributed.
Order Statistics(Selection Problem) A more interesting problem is selection:  finding the i th smallest element of a set We will show: –A practical randomized.
CS 3343: Analysis of Algorithms Lecture 14: Order Statistics.
Medians and Order Statistics
1 Selection --Medians and Order Statistics (Chap. 9) The ith order statistic of n elements S={a 1, a 2,…, a n } : ith smallest elements Also called selection.
Introduction to Algorithms
Introduction to Algorithms Jiafen Liu Sept
Chapter 4: Divide and Conquer Master Theorem, Mergesort, Quicksort, Binary Search, Binary Trees The Design and Analysis of Algorithms.
Spring 2015 Lecture 5: QuickSort & Selection
1 Sorting Problem: Given a sequence of elements, find a permutation such that the resulting sequence is sorted in some order. We have already seen: –Insertion.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Quicksort CIS 606 Spring Quicksort Worst-case running time: Θ(n 2 ). Expected running time: Θ(n lg n). Constants hidden in Θ(n lg n) are small.
Median, order statistics. Problem Find the i-th smallest of n elements.  i=1: minimum  i=n: maximum  i= or i= : median Sol: sort and index the i-th.
Selection: Find the ith number
Median and Order Statistics Jeff Chastine. Medians and Order Statistics The i th order statistic of a set of n elements is the i th smallest element The.
David Luebke 1 8/17/2015 CS 332: Algorithms Linear-Time Sorting Continued Medians and Order Statistics.
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Chapter 9: Selection Order Statistics What are an order statistic? min, max median, i th smallest, etc. Selection means finding a particular order statistic.
Order Statistics ● The ith order statistic in a set of n elements is the ith smallest element ● The minimum is thus the 1st order statistic ● The maximum.
Order Statistics(Selection Problem)
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
1 Algorithms CSCI 235, Fall 2015 Lecture 19 Order Statistics II.
COSC 3101A - Design and Analysis of Algorithms 4 Quicksort Medians and Order Statistics Many of these slides are taken from Monica Nicolescu, Univ. of.
CSC317 1 Quicksort on average run time We’ll prove that average run time with random pivots for any input array is O(n log n) Randomness is in choosing.
Randomized Quicksort (8.4.2/7.4.2) Randomized Quicksort –i = Random(p, r) –swap A[p]  A[i] –partition A(p, r) Average analysis = Expected runtime –solving.
David Luebke 1 6/26/2016 CS 332: Algorithms Linear-Time Sorting Continued Medians and Order Statistics.
David Luebke 1 7/2/2016 CS 332: Algorithms Linear-Time Sorting: Review + Bucket Sort Medians and Order Statistics.
Chapter 9: Selection of Order Statistics What are an order statistic? min, max median, i th smallest, etc. Selection means finding a particular order statistic.
Analysis of Algorithms CS 477/677
Order Statistics.
Order Statistics Comp 122, Spring 2004.
CPSC 311 Section 502 Analysis of Algorithm
Divide and Conquer Strategy
Linear-Time Sorting Continued Medians and Order Statistics
Randomized Algorithms
QuickSort QuickSort Best, Worst Average Cases K-th Ordered Statistic
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
Order Statistics(Selection Problem)
Chapter 4: Divide and Conquer
Quick Sort (11.2) CSE 2011 Winter November 2018.
Dr. Yingwu Zhu Chapter 9, p Linear Time Selection Dr. Yingwu Zhu Chapter 9, p
Randomized Algorithms
Lecture 3 / 4 Algorithm Analysis
Medians and Order Statistics
Quick sort and Radix sort
Topic: Divide and Conquer
Lecture No 6 Advance Analysis of Institute of Southern Punjab Multan
CS 3343: Analysis of Algorithms
Order Statistics Comp 550, Spring 2015.
EE 312 Software Design and Implementation I
CS 3343: Analysis of Algorithms
Algorithms: Design and Analysis
Chapter 7 Quicksort.
Chapter 9: Medians and Order Statistics
Topic: Divide and Conquer
Algorithms CSCI 235, Spring 2019 Lecture 20 Order Statistics II
Order Statistics Comp 122, Spring 2004.
Chapter 9: Selection of Order Statistics
CS 583 Analysis of Algorithms
The Selection Problem.
Quicksort and Randomized Algs
Algorithms CSCI 235, Spring 2019 Lecture 19 Order Statistics
CS200: Algorithm Analysis
Analysis of Algorithms CS 477/677
Medians and Order Statistics
Chapter 11 Sets, and Selection
Presentation transcript:

Order Statistics Def: Let A be an ordered set containing n elements. The i-th order statistic is the i-th smallest element. Minimum: 1st order statistic Maximum: n-th order statistic Median: -th order statistic The Selection Problem: Find the i-th order statistic for a given i. Input: A set A of n (distinct) numbers and a number i, 1  i  n. Output: The element x  A that is larger than exactly (i -1) elements of A. Naive selection: sort A and return A[i]. Time complexity: O(nlgn). Can we do better??

Finding Minimum (Maximum) Minimum(A) 1. min = A[1] 2. for i = 2 to A.length 3. if min > A[i] 4. min = A[i] 5. return min cf. The hiring problem in Chapter 5 Exactly n-1 comparisons. Best possible? Expected # of times executed for line 4: O(lgn). Naive simultaneous minimum and maximum: 2n-3 comparisons.

Simultaneous Minimum and Maximum T(n): # of comparisons used for n elements. Assume n = 2k. T(n) = 2T(n/2) + 2 = 2(2T(n/4) + 2) + 2 = 2k-1T(2) + (2k-1 + 2k-2 + … + 2) = 2k-1 + 2k - 2 = 3n/2 - 2 This divide-and-conquer algorithm is optimal!

Selection in Linear Expected Time Randomized-Select(A,p,r,i) 1. if p == r 2. return A[p] 3. q = Randomized-Partition(A,p,r) 4. k = q – p + 1 5. if i  k 6. return Randomized-Select(A,p,q,i) 7. else return Randomized-Select(A,q+1,r, i-k) Randomized-Partition first swaps A[p] with a random element of A and then proceeds as in regular PARTITION. Randomized-Select is like Randomized-Quicksort, except that we only need to make one recursive call. Time complexity Worst case: 1:n-1 partitions. T(n) = T(n-1) + (n) = (n2) Best case: T(n) = (n) Average case? Like quicksort, asymptotically close to best case.

Selection in Linear Expected Time: Average Case Assume T(n)  cn. Thus, on average, Randomized-Select runs in linear time.

Selection in Worst-Case Linear Time Key: Guarantee a good split when array is partitioned. Select(A, p, r, i) Divide input array A into  n/5 groups of size 5 (possibly with a leftover group of size < 5). Find the median of each of the n/5 groups. Call Select recursively to find the median x of the n/5 medians. Partition array around x, splitting it into two arrays of A[p, q] (with k elements) and A[q+1, r] (with n-k elements). if (i  k) then Select(A, p, q, i) else Select(A, q + 1, r, i - k). Spring 2013

Runtime Analysis Main idea: Select guarantees that x causes a good partition; at least elements > x (or < x)  worst-case split has 7n/10 + 6 elements in the bigger subproblem. Run time: T(n) = T( n/5 ) + T(7n/10+6) + O(n). O(n): break into groups. O(n): finding medians (constant time for 5 elements). T(n/5): recursive call to find median of the medians. O(n): partition. T(7n/10+6): searching in the bigger partition. Apply the substitution method to prove that T(n)=O(n).