CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009.

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

110/6/2014CSE Suprakash Datta datta[at]cse.yorku.ca CSE 3101: Introduction to the Design and Analysis of Algorithms.
Lower Bounds for Sorting, Searching and Selection
QuickSort Average Case Analysis An Incompressibility Approach Brendan Lucier August 2, 2005.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Lower Bounds & Models of Computation Jeff Edmonds York University COSC 3101 Lecture 8.
Lower bound for sorting, radix sort COMP171 Fall 2005.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
CPSC 668Set 10: Consensus with Byzantine Failures1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
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.
CS2420: Lecture 13 Vladimir Kulyukin Computer Science Department Utah State University.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
CPSC 668Set 10: Consensus with Byzantine Failures1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
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.
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
1 Today’s Material Lower Bounds on Comparison-based Sorting Linear-Time Sorting Algorithms –Counting Sort –Radix Sort.
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
Sorting in Linear Time Lower bound for comparison-based sorting
CSE 373 Data Structures Lecture 15
The Lower Bounds of Problems
Sorting Fun1 Chapter 4: Sorting     29  9.
Analysis of Algorithms CS 477/677
Fall 2015 Lecture 4: Sorting in linear time
Sorting Conclusions David Kauchak cs302 Spring 2013.
CSC 213 Lecture 13: Writing Code & Sorting Lowest Bound.
1 Lower Bound on Comparison-based Search We have now covered lots of searching methods –Contiguous Data (Arrays) Sequential search Binary Search –Dynamic.
Midterm Review 1. Midterm Exam Thursday, October 15 in classroom 75 minutes Exam structure: –TRUE/FALSE questions –short questions on the topics discussed.
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.
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.
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.
1 Section 5.1 Analyzing Algorithms Let P be a problem and A an algorithm to solve P. The running time of A can be analyzed by counting the number of certain.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Lower Bounds & Sorting in Linear Time
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
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
Trees.
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.
Lower Bound Theory.
CSCE 411 Design and Analysis of Algorithms
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS200: Algorithm Analysis
Lower Bounds & Sorting in Linear Time
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Topic 5: Heap data structure heap sort Priority queue
Lower bound for sorting, radix sort
Copyright © Aiman Hanna All rights reserved
CPSC 411 Design and Analysis of Algorithms
David Kauchak cs302 Spring 2012
CS 583 Analysis of Algorithms
Presentation transcript:

CPSC 411, Fall 2008: Set 2 1 CPSC 311 Analysis of Algorithms Sorting Lower Bound Prof. Jennifer Welch Fall 2009

CPSC 411, Fall 2008: Set 22 Comparison Based Sorting All these algorithms are comparison based the behavior depends on relative values of keys, not exact values behavior on [1,3,2,4] is same as on [9,25,23,99] Fastest of these algorithms was O(nlog n). We will show that's the best you can get with comparison based sorting.

CPSC 411, Fall 2008: Set 23 Decision Tree Consider any comparison based sorting algorithm Represent its behavior on all inputs of a fixed size with a decision tree Each tree node corresponds to the execution of a comparison Each tree node has two children, depending on whether the parent comparison was true or false Each leaf represents correct sorted order for that path

CPSC 411, Fall 2008: Set 24 Decision Tree Diagram first comparison: check if a i ≤ a j second comparison if a i ≤ a j : check if a k ≤ a l second comparison if a i > a j : check if a m ≤ a p third comparison if a i ≤ a j and a k ≤ a l : check if a x ≤ a y YES NO

CPSC 411, Fall 2008: Set 25 Insertion Sort for j := 2 to n to key := a[j] i := j-1 while i > 0 and a[i] > key do a[i]+1 := a[i] i := i -1 endwhile a[i+1] := key endfor

CPSC 411, Fall 2008: Set 26 Insertion Sort for n = 3 a 1 ≤ a 2 ? a 2 ≤ a 3 ?a 1 ≤ a 3 ? a 2 ≤ a 3 ? NOYES 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 3 a 2 a 1 a 2 a 1 a 3 NO YES

CPSC 411, Fall 2008: Set 27 Insertion Sort for n = 3 a 1 ≤ a 2 ? NO a 2 ≤ a 3 ?a 1 ≤ a 3 ? a 2 ≤ a 3 ? YES 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 3 a 2 a 1 a 2 a 1 a 3 NO YES

CPSC 411, Fall 2008: Set 28 How Many Leaves? Must be at least one leaf for each permutation of the input otherwise there would be a situation that was not correctly sorted Number of permutations of n keys is n!. Idea: since there must be a lot of leaves, but each decision tree node only has two children, tree cannot be too shallow depth of tree is a lower bound on running time

CPSC 411, Fall 2008: Set 29 Key Lemma Height of a binary tree with n! leaves is  (n log n). Proof: Maximum number of leaves in a binary tree with height h is 2 h. h = 1, 2 1 leaves h = 2, 2 2 leaves h = 3, 2 3 leaves

CPSC 411, Fall 2008: Set 210 Proof of Lemma Let h be height of decision tree. Number of leaves in decision tree, which is n!, is at most 2 h. 2 h ≥ n! h ≥ log(n!) = log(n(n-1)(n-1)…(2)(1)) ≥ (n/2)log(n/2) by algebra =  (n log n)

CPSC 411, Fall 2008: Set 211 Finishing Up Any binary tree with n! leaves has height  (n log n). Decision tree for any c-b sorting alg on n keys has height  (n log n). Any c-b sorting alg has at least one execution with  (n log n) comparisons Any c-b sorting alg has  (n log n) worst- case running time.