The Selection Algorithm : Design & Analysis [10].

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

110/6/2014CSE Suprakash Datta datta[at]cse.yorku.ca CSE 3101: Introduction to the Design and Analysis of Algorithms.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
MS 101: Algorithms Instructor Neelima Gupta
Lower Bounds for Sorting, Searching and Selection
MS 101: Algorithms Instructor Neelima Gupta
Lower bound: Decision tree and adversary argument
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
MS 101: Algorithms Instructor Neelima Gupta
§7 Quicksort -- the fastest known sorting algorithm in practice 1. The Algorithm void Quicksort ( ElementType A[ ], int N ) { if ( N < 2 ) return; pivot.
Lecture 12: Lower bounds By "lower bounds" here we mean a lower bound on the complexity of a problem, not an algorithm. Basically we need to prove that.
CSC 2300 Data Structures & Algorithms March 16, 2007 Chapter 7. Sorting.
Deterministic Selection and Sorting Prepared by John Reif, Ph.D. Analysis of Algorithms.
COSC 3100 Transform and Conquer
Lecture 13: Adversary Arguments continues … This lecture, we continue with the adversary argument by giving more examples.
Finding the Median Algorithm : Design & Analysis [11]
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.
Lower bound for sorting, radix sort COMP171 Fall 2006.
Lecture 5: Linear Time Sorting Shang-Hua Teng. Sorting Input: Array A[1...n], of elements in arbitrary order; array size n Output: Array A[1...n] of the.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
Sorting Heapsort Quick review of basic sorting methods Lower bounds for comparison-based methods Non-comparison based sorting.
Comp 122, Spring 2004 Lower Bounds & Sorting in Linear Time.
Lecture 25 Selection sort, reviewed Insertion sort, reviewed Merge sort Running time of merge sort, 2 ways to look at it Quicksort Course evaluations.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Lecture 5: Master Theorem and Linear Time Sorting
Chapter 11: Limitations of Algorithmic Power
Analysis of Algorithms CS 477/677
CSC 2300 Data Structures & Algorithms March 20, 2007 Chapter 7. Sorting.
Problem: Selection Design and Analysis: Adversary Arguments The selection problem >  Finding max and min Adversary Arguments( 反论 )  Suppose you are playing.
10/15/2002CSE More on Sorting CSE Algorithms Sorting-related topics 1.Lower bound on comparison sorting 2.Beating the lower bound 3.Finding.
Sorting Lower Bound1. 2 Comparison-Based Sorting (§ 4.4) Many sorting algorithms are comparison based. They sort by making comparisons between pairs of.
Lower Bounds for Comparison-Based Sorting Algorithms (Ch. 8)
Computer Algorithms Lecture 11 Sorting in Linear Time Ch. 8
CSE 373 Data Structures Lecture 15
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
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.
Jessie Zhao Course page: 1.
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.
Analysis of Algorithms CS 477/677
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
TECH Computer Science Problem: Selection Design and Analysis: Adversary Arguments The selection problem >  Finding max and min Designing against an adversary.
Bucket & Radix Sorts. Efficient Sorts QuickSort : O(nlogn) – O(n 2 ) MergeSort : O(nlogn) Coincidence?
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.
Asymptotic Behavior Algorithm : Design & Analysis [2]
COSC 3101A - Design and Analysis of Algorithms 6 Lower Bounds for Sorting Counting / Radix / Bucket Sort Many of these slides are taken from Monica Nicolescu,
A method for obtaining lower bounds
Linear Sorting. Comparison based sorting Any sorting algorithm which is based on comparing the input elements has a lower bound of Proof, since there.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
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.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Chapter 8-1: Lower Bound of Comparison Sorts. 2 About this lecture Lower bound of any comparison sorting algorithm – applies to insertion sort, selection.
Sorting Lower Bound 4/25/2018 8:49 PM
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Lecture 5 Algorithm Analysis
Analysis and design of algorithm
Lecture 5 Algorithm Analysis
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
Chapter 11 Limitations of Algorithm Power
Lecture 5 Algorithm Analysis
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Lower bound for sorting, radix sort
CS 583 Analysis of Algorithms
The Selection Problem.
Lecture 5 Algorithm Analysis
Presentation transcript:

The Selection Algorithm : Design & Analysis [10]

In the last class … Accelerated Heapsort Analysis by Recursion Tree Analysis by Guess and Inductive Proof Shell Sort Radix Sort

The Selection The Selection Problems Finding max and min Finding the second largest key Adversary argument Adversary argument and lower bound

The Selection Problem Problem: Suppose E is an array containing n elements with keys from some linearly order set, and let k be an integer such that 1  k  n. The selection problem is to find an element with the kth smallest key in E.

A Special Case: Finding the Max FindMax Input: number array E with n entries indexed as 1, … n Output: Return max, the largest entry in E Procedure: int findMax(E,n) max=E(1) for (index=1;index<n;index++) if (max<E(index) max=E(index); return max

Lower Bound of Finding the Max For any algorithm A that can compare and copy numbers exclusively, if A does fewer than n-1 comparisons in any case, we can always provide a right input so that A will output a wrong result. Proof: There is at least one element, say, E[k], which never be checked by A. Given two input E ’, E ” with all the elements same except the kth element, and for E ’, the kth element is the largest element, but for E ”, it ’ s not. Then, at least one of the outputs is wrong. Since the decision tree for the selection problem must have at least n leaves, the height of the tree is at least  lgn . It’s not a good lower bound.

Finding max and min The strategy Pair up the keys, and do n/2 comparisons(if n odd, having E[n] uncompared); Doing findMax for larger key set and findMin for small key set respectively(if n odd, E[n] included in both sets) Number of comparisons For even n: n/2+2(n/2-1)=3n/2-2 For odd n: (n-1)/2+2((n-1)/2+1-1)=  3n/2  -2

Unit of Information Concerning max and min That x is max can only be known when it is sure that every key other than x has lost some comparison. That y is min can only be known when it is sure that every key other than y has win some comparison. Each win or loss is counted as one unit of information, then any algorithm must have at least 2n-2 units of information to be sure of specifying the max and min.

Adversay Strategy

Proving the Lower Bound by Adversary Strategy Construct a input to force the algorithm to do more comparisons as possible, that is, to give away as few as possible units of new information with each comparison. It can be achieved that 2 units of new information are given away only when the status is N,N. It is always possible to give adversary response for other status so that at most one new unit of information is given away, without any inconsistencies. So, the Lower Bound is n/2+n-2(for even n)

An Example Using Adversary

Adversary Argument Imaging an “ adversary ” who are try best to keep down. Adversary “ constucts ” the “ worst case ” input step by step. The “ good ” adversary rules try to be able to thwart any algorithm. The only constraint on the adversary ’ s answer is that they must be internally consistent.

Finding the Second-Largest Key Using FindMax twice is a solution with 2n-3 comparisons. For a better algorithm, the idea is to collect some useful information from the first FindMax to decrease the number of comparisons in the second FindMax. Useful information: the key which lost to a key other than max cannot be the second-Largest key. The worst case for twice FindMax is “ No information ”.

Finding Second Largest Key Using Tournament x 2 is max Only x 1, x 3, x 5, x 6 may be the second largest key. Larger key bubbles up The length of the longest path is  lgn , as many as those compared to max at most.

Analysis of Finding the Second Any algorithm that finds secondLargest must also find max before. (n-1) The secondLargest can only be in those which lose directly to max. On its path along which bubbling up to the root of tournament tree, max beat  lgn  keys at most. Pick up secondLargest. (  lgn  -1) n+  lgn  -2

Lower Bound by Adversary Theorem Any algorithm (that works by comparing keys) to find the second largest in a set of n keys must do at least n+  lgn  -2 comparisons in the worst case. Proof There is an adversary strategy that can force any algorithm that finds secondLargest to compare max to  lgn  distinct keys.

Assigning a weight w(x) to each key. The initial values are all 1. Adversary rules: Weighted Key Note: for one comparison, the weight increasing is no more than doubled. Zero=Loss

Lower Bound by Adversary: Details Note: the sum of weights is always n. Let x is max, then x is the only nonzero weighted key, that is w(x)=n. By the adversary rules: w k (x)  2w k-1 (x) Let K be the number of comparisons x wins against previously undefeated keys: n=w K (x)  2 K w 0 (x)=2 K So, K  lgn 

Home Assignments