Algorithms CSCI 235, Spring 2019 Lecture 19 Order Statistics

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

Order Statistics Sorted
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.
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
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.
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.
Tirgul 4 Order Statistics Heaps minimum/maximum Selection Overview
Order Statistics. Selection Problem Input: a set A of n distinct numbers and a number i where i
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.
Order Statistics. Order statistics Given an input of n values and an integer i, we wish to find the i’th largest value. There are i-1 elements smaller.
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.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
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.
Instructor Neelima Gupta Table of Contents Review of Lower Bounding Techniques Decision Trees Linear Sorting Selection Problems.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
1 Algorithms CSCI 235, Fall 2015 Lecture 17 Linear Sorting.
1 Algorithms CSCI 235, Fall 2015 Lecture 19 Order Statistics II.
Mudasser Naseer 1 1/25/2016 CS 332: Algorithms Lecture # 10 Medians and Order Statistics Structures for Dynamic Sets.
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.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting So Far Insertion sort: –Easy to code –Fast on small inputs (less than ~50 elements) –Fast on nearly-sorted.
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.
4/17/2003CSE More on Sorting CSE Algorithms Sorting-related topics 1.Lower bound on comparison sorting 2.Beating the lower bound 3.Finding.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Sorting.
Order Statistics.
Order Statistics Comp 122, Spring 2004.
Median Finding Algorithm
Algorithms CSCI 235, Fall 2017 Lecture 13 Elementary Sorts II
Heapsort CSE 373 Data Structures.
Linear-Time Sorting Continued Medians and Order Statistics
Randomized Algorithms
Algorithm design and Analysis
Linear Sorting Sections 10.4
Randomized Algorithms
Sorting Algorithms Ellysa N. Kosinaya.
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
Medians and Order Statistics
Topic: Divide and Conquer
Sorting … and Insertion Sort.
Order Statistics Comp 550, Spring 2015.
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
Noncomparison Based Sorting
Heapsort CSE 373 Data Structures.
EE 312 Software Design and Implementation I
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.
Algorithms: Design and Analysis
Chapter 9: Medians and Order Statistics
Algorithms CSCI 235, Spring 2019 Lecture 18 Linear Sorting
Topic: Divide and Conquer
Elementary Sorting Algorithms
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.
Grade 12 Essential Math Measurement and Statistics
Algorithms CSCI 235, Spring 2019 Lecture 2 Introduction to Asymptotic Analysis Read Ch. 2 and 3 of Text 1.
Algorithms CSCI 235, Spring 2019 Lecture 26 Midterm 2 Review
Algorithms CSCI 235, Spring 2019 Lecture 13 Elementary Sorts II
Algorithms CSCI 235, Spring 2019 Lecture 17 Quick Sort II
CS200: Algorithm Analysis
Medians and Order Statistics
Presentation transcript:

Algorithms CSCI 235, Spring 2019 Lecture 19 Order Statistics

Bucket Sort Bucket sort is like counting-sort except it can be used when the keys are not integers. If the keys are relatively evenly distributed, we can use a general bucket sort. Idea: 1) If you have n elements in a given range, sort them into buckets that divide this range into portions of width 1/n. Do this by first creating an array of n buckets, each containing an empty list. 2) Insert each element into the list associated with the bucket whose range matches that element's value. 3) Sort each of the lists in the buckets. 4) Read elements from the lists in order back into the input array.

Example A 0.78 0.17 0.39 0.26 0.72 0.94 0.21 0.12 0.23 10 0.68

Analyzing bucket sort Is bucket-sort stable? Is it in place? Worst case running time of Bucket sort: Best case running time: Average case:

Order Statistics Suppose we want to find the ith smallest (or largest) item in an array. Can we find it in less than Q(nlgn) time? Definitions: If S is a set of n distinct elements, the ith order statistic is the ith smallest element. (i.e. it is the element that is larger than i-1 elements in the set). The ith order statistic has rank i. The minimum of the set = the 1st order statistic (rank = 1) The maximum of the set = the nth order statistic (rank = n)

The Median The median of S is the element in the middle of the set (the "halfway point"). If n is odd, the median is rank (n+1)/2. E.g. S = {5, 3, 1, 9, 7}; Median is? If n is even, we have two medians: n/2 and (n/2 + 1) E.g. S = {5, 3, 1, 9, 7, 11}; Medians are? Therefore, the median(s) of S is (are) the element(s) with rank: Example: B = {43, 5, 17, 91, 2, 42, 19, 72, 37, 3} BORDERED = {2, 3, 5, 17, 19, 37, 42, 43, 72, 91} Minimum = ? Maximum = ? Median(s) = ? Rank of 17 = ?

The Selection Problem Write an algorithm, Select(A,i), that returns the ith order statistic from an array of n distinct elements. Obvious solution: What is the lowest running time for this? Can we do better than this?

Finding Max and Min Minimum(A) min <- A[1] for i <- 2 to length(A) do if min > A[i] then min <- A[i] return min Maximum(A) is similar. What is the running time? Can we do better?

Simultaneous Max and Min Algorithm A: 1) Find minimum (n-1) comparisons 2) Find maximum (n-1) comparisons Total: 2n - 2 comparisons. Algorithm B: Find max and min simultaneously 1) Store value of max and min seen so far 2) Compare 2 input elements with each other a) Compare the smaller of the two with the current min b) Compare the larger of the two with the current max 3) Continue with next pair of elements Algorithm B makes 3 comparisons for each pair of elements. Total comparisons = Example: A = {3, 4, 17, 12, 1, 5, 21}

Selection of kth order statistic We can find the kth element by repeatedly finding the minimum and discarding it. Example: B = {43, 5, 17, 91, 2, 42, 19, 72, 37, 3} Find the 4th element: Running time: We can use a similar method for finding the (n-k)th order statistic, by working with the maximum. (Find the maximum and discard). General running time for finding kth order statistic:

Finding the median Note that the position of the median changes with n. As n increases, so does the median (n/2). If we apply the previous strategy: T(n) = ? Can we do better? (Tune in next time...)