110/6/2014CSE 31011 Suprakash Datta datta[at]cse.yorku.ca CSE 3101: Introduction to the Design and Analysis of Algorithms.

Slides:



Advertisements
Similar presentations
CPSC 411 Design and Analysis of Algorithms Set 2: Sorting Lower Bound Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 2 1.
Advertisements

CS16: Introduction to Data Structures & Algorithms
Introduction to Algorithms Quicksort
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Lower Bounds for Sorting, Searching and Selection
BackTracking Algorithms
QuickSort Average Case Analysis An Incompressibility Approach Brendan Lucier August 2, 2005.
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
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Using Divide and Conquer for Sorting
Discrete Structure Li Tak Sing( 李德成 ) Lectures
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.
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.
Comp 122, Spring 2004 Lower Bounds & Sorting in Linear Time.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 4 Comparison-based sorting Why sorting? Formal analysis of Quick-Sort Comparison.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CPSC 411, Fall 2008: Set 2 1 CPSC 411 Design and Analysis of Algorithms Set 2: Sorting Lower Bound Prof. Jennifer Welch Fall 2008.
CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009.
Lecture 5: Master Theorem and Linear Time Sorting
CSE 326: Data Structures Sorting Ben Lerner Summer 2007.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Analysis of Algorithms CS 477/677
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
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
Data Structure & Algorithm Lecture 7 – Linear Sort JJCAO Most materials are stolen from Prof. Yoram Moses’s course.
CSE 373 Data Structures Lecture 15
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
The Lower Bounds of Problems
CSC 213 Lecture 13: Writing Code & Sorting Lowest Bound.
Instructor Neelima Gupta Table of Contents Review of Lower Bounding Techniques Decision Trees Linear Sorting Selection Problems.
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,
LIMITATIONS OF ALGORITHM POWER
CSCE 411H Design and Analysis of Algorithms Set 10: Lower Bounds Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 10 1 * Slides adapted.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Linear Sorting. Comparison based sorting Any sorting algorithm which is based on comparing the input elements has a lower bound of Proof, since there.
The Selection Algorithm : Design & Analysis [10].
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.
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.
Lower Bounds & Sorting in Linear Time
David Kauchak cs062 Spring 2010
Sorting Lower Bound 4/25/2018 8:49 PM
Decision trees Polynomial-Time
CPSC 411 Design and Analysis of Algorithms
CSCE 411 Design and Analysis of Algorithms
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Lecture 5 Algorithm Analysis
Lower Bound Theory.
CSCE 411 Design and Analysis of Algorithms
Lecture 5 Algorithm Analysis
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS200: Algorithm Analysis
Lower Bounds & Sorting in Linear Time
Lecture 5 Algorithm Analysis
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Topic 5: Heap data structure heap sort Priority queue
CPSC 411 Design and Analysis of Algorithms
David Kauchak cs302 Spring 2012
CS 583 Analysis of Algorithms
Lecture 5 Algorithm Analysis
Presentation transcript:

110/6/2014CSE Suprakash Datta datta[at]cse.yorku.ca CSE 3101: Introduction to the Design and Analysis of Algorithms

2 Lower bounds What are we counting? Running time? Memory? Number of times a specific operation is used? What (if any) are the assumptions? Is the model general enough? Here we are interested in lower bounds for the WORST CASE. So we will prove (directly or indirectly): for any algorithm for a given problem, for each n>0, there exists an input that make the algorithm take  (f(n)) time. Then f(n) is a lower bound on the worst case running time.

3 Comparison-based algorithms Finished looking at comparison-based sorts. Crucial observation: All the sorts work for any set of elements – numbers, records, objects, …… Only require a comparator for two elements. #include void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); DESCRIPTION: The qsort() function sorts an array with nmemb elements of size size. The base argument points to the start of the array. The contents of the array are sorted in ascending order according to a comparison function pointed to by compar, which is called with two arguments that point to the objects being compared.

4 Comparison-based algorithms The algorithm only uses the results of comparisons, not values of elements (*). Very general – does not assume much about what type of data is being sorted. However, other kinds of algorithms are possible! In this model, it is reasonable to count #comparisons. Note that the #comparisons is a lower bound on the running time of an algorithm. (*) If values are used, lower bounds proved in this model are not lower bounds on the running time.

5 Lower bound for a simpler problem Let ’ s start with a simple problem. Minimum of n numbers Minimum (A)  min = A[1]  for i = 2 to length[A]  do if min >= A[i]  then min = A[i]  return min Can we do this with fewer comparisons? We have seen very different algorithms for this problem. How can we show that we cannot do better by being smarter?

6 Lower bounds for the minimum Claim: Any comparison-based algorithm for finding the minimum of n keys must use at least n-1 comparisons. Proof: If x,y are compared and x > y, call x the winner. Any key that is not the minimum must have won at least one comparison. WHY? Each comparison produces exactly one winner and at most one NEW winner.  at least n-1 comparisons have to be made.

7 Points to note Crucial observations: We proved a claim about ANY algorithm that only uses comparisons to find the minimum. Specifically, we made no assumptions about 1.Nature of algorithm. 2.Order or number of comparisons. 3.Optimality of algorithm 4.Whether the algorithm is reasonable – e.g. it could be a very wasteful algorithm, repeating the same comparisons.

8 On lower bound techniques Unfortunate facts: Lower bounds are usually hard to prove. Virtually no known general techniques – must try ad hoc methods for each problem.

9 Lower bounds for comparison-based sorting Trivial:  (n) – every element must take part in a comparison. Best possible result –  (n log n) comparisons, since we already know several O(n log n) sorting algorithms. Proof is non-trivial: how do we reason about all possible comparison-based sorting algorithms?

10 The Decision Tree Model Assumptions: –All numbers are distinct (so no use for a i = a j ) –All comparisons have form a i  a j ( since a i  a j, a i  a j, a i a j are equivalent ). Decision tree model –Full binary tree –Ignore control, movement, and all other operations, just use comparisons. –suppose three elements with instance.

11 Example: insertion sort (n=3) A[2]: A[3] A[1]: A[3] A[1]: A[2] A[1]: A[3] A[2]: A[3] > > > > >      A[1]A[2]A[3] A[1]A[3]A[2] A[3]A[1]A[2] A[2]A[3]A[1] A[2]A[1]A[3] A[3]A[2]A[1]

12 The Decision Tree Model 2:3 1:2 2:3 1:3    > > > > > Internal node i:j indicates comparison between a i and a j. Leaf node indicates ordering a  (1)  a  (2)  a  (3). Path of bold lines indicates sorting path for. There are total 3!=6 possible permutations (paths). 

13 Summary  Only consider comparisons  Each internal node = 1 comparison  Start at root, make the first comparison - if the outcome is  take the LEFT branch - if the outcome is > - take the RIGHT branch  Repeat at each internal node  Each LEAF represents ONE correct ordering

14 Intuitive idea Subset S 1 of S s.t. x[i]  x[j] Subset S 2 of S s.t. x[i] > x[j] S x[i] : x[j]  > S is a set of permutations

15 Lower bound for the worst case Claim: The decision tree must have at least n! leaves. WHY? worst case number of comparisons= the height of the decision tree. Claim: Any comparison sort in the worst case needs  (n log n) comparisons. Suppose height of a decision tree is h, number of paths (i,e,, permutations) is n!. Since a binary tree of height h has at most 2 h leaves, n!  2 h, so h  lg (n!)   (n lg n)