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.

Slides:



Advertisements
Similar presentations
Heapsort O(n lg n) worst case Another design paradigm –Use of a data structure (heap) to manage information during execution of algorithm Comparision-based.
Advertisements

Heapsort O(n lg n) worst case Another design paradigm –Use of a data structure (heap) to manage information during execution of algorithm Comparision-based.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
MS 101: Algorithms Instructor Neelima Gupta
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2010.
Lower bound for sorting, radix sort COMP171 Fall 2005.
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.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Tyler Robison Summer
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.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
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.
Sorting in Linear Time Lower bound for comparison-based sorting
CSE 373 Data Structures Lecture 15
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
David Luebke 1 10/13/2015 CS 332: Algorithms Linear-Time Sorting Algorithms.
CSC 41/513: Intro to Algorithms Linear-Time Sorting Algorithms.
CSE373: Data Structures & Algorithms Lecture 20: Beyond Comparison Sorting Dan Grossman Fall 2013.
Introduction to Algorithms Jiafen Liu Sept
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.
Sorting Fun1 Chapter 4: Sorting     29  9.
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2012.
Analysis of Algorithms CS 477/677
Sorting Lower Bounds Amihood Amir Bar-Ilan University 2014.
Mudasser Naseer 1 11/5/2015 CSC 201: Design and Analysis of Algorithms Lecture # 8 Some Examples of Recursion Linear-Time Sorting Algorithms.
Instructor Neelima Gupta Table of Contents Review of Lower Bounding Techniques Decision Trees Linear Sorting Selection Problems.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.
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,
Sorting 1. Insertion Sort
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.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
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.
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.
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
CPSC 411 Design and Analysis of Algorithms
Introduction to Algorithms
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Chapter 8-2: Sorting in Linear Time
Analysis of Algorithms
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS200: Algorithm Analysis
Linear Sorting Sorting in O(n) Jeff Chastine.
Linear Sort "Our intuition about the future is linear. But the reality of information technology is exponential, and that makes a profound difference.
Lower Bounds & Sorting in Linear Time
Linear-Time Sorting Algorithms
Lecture 5 Algorithm Analysis
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
CPSC 411 Design and Analysis of Algorithms
David Kauchak cs302 Spring 2012
CS 583 Analysis of Algorithms
The Selection Problem.
Presentation transcript:

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 sort, merge sort, heapsort, quicksort, … – does not apply to counting sort, radix sort, bucket sort Based on Decision Tree Model

3 Comparison Sort Comparison sort only uses comparisons between items to gain information about the relative order of items It’s like the elements are stored in boxes, and we can only pick two boxes at a time to compare which one is larger …

4 Worst-Case Running Time Merge sort and heapsort are the “smartest” comparison sorting algorithms we have studied so far: worst-case running time is  (n log n) Question: Do we have an even smarter algorithm? Say, runs in  (n log n) time? Answer: No! (main theorem in this lecture)

5 Lower Bound Theorem: Any comparison sorting algorithm requires  (n log n) comparisons to sort n distinct items in the worst case Corollary: Any comparison sorting algorithm runs in  (n log n) time in the worst case Corollary: Merge sort and Heapsort are (asymptotically) optimal comparison sorts

6 Proof of Lower Bound The main theorem only counts comparison operations, so we may assume all other operations (such as moving items) are for free Consequently, any comparison sort can be viewed as performing in the following way: 1.Continuously gather relative ordering information between items 2.In the end, move items to correct positions We use the above view in the proof

7 Decision Tree of an Algorithm Consider the following algorithm to sort 3 items A, B, and C: Step 1: Compare A with B Step 2: Compare B with C Step 3: Compare A with C Afterwards, decide the sorting order of the 3 items

8 The previous algorithm always use 3 comparisons, and can sort the 3 items In particular, the comparisons used in different inputs (i.e., permutations) can be captured in a decision tree, as shown in the next slide: Decision Tree of an Algorithm

9 A : B B : C > < <>>< result of decision decision A : C <><> <><> sorting order decidedimpossible case A< B < CA< C< BC<A<B B<A<CB<C<AC<B<A

10 A cleverer algorithm may sort the 3 items, sometimes, using at most 2 comparisons: Step 1: Check if A > B Step 2: Check if B > C Step 3: Compare A with C if the result in Steps 1 and 2 are different Afterwards, decide the sorting order Then, the decision tree becomes … Decision Tree of an Algorithm

11 A : B B : C > < <>>< result of decision decision A : C <> <> sorting order decided A< B < C A< C< BC<A<B B<A<CB<C<A C<B<A

12 Properties of Decision Tree In general, assume the input has n items Then, for ANY comparison sort algorithm: Each of the n! permutations corresponds to a distinct leaf in the decision tree The height of the tree is the worst- case # of comparisons for any input Question: What can be the height of the decision tree of the cleverest algorithm?

13 Lower Bound on Height There are n! leaves [for any decision tree] Degree of each node is at most 2 Let h = node-height of decision tree So, n! = total # leaves ≤ 2 h  h ≥ log (n!) = log n + log (n-1) + … ≥ log n + … + log (n/2) ≥ (n/2) log (n/2) =  (n log n) We can also use Stirling’s approximation: n! =  2  n (n/e) n (1+  (1/n))

14 Proof of Lower Bound Conclusion: worst-case # of comparisons = node-height of the decision tree =  (n log n) [for any decision tree]  Any comparison sort, even the cleverest one, needs  (n log n) comparisons in the worst case  Heapsort and merge sort are asymptotically optimal comparison sorts

15 Homework Problem 1: (a) Please give an optimal decision tree with four elements a, b, c, and d. (b) Please give a decision tree for insertion sort operating on four elements a, b, c, and d. Practice at home 8.1-3, 8.1-4