David Kauchak cs302 Spring 2012

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
Lower bound: Decision tree and adversary argument
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Lower bound for sorting, radix sort COMP171 Fall 2005.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
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.
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 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
Sorting Chapter 6. 2 Algorithms to know Insertion Sort Insertion Sort –O(n 2 ) but very efficient on partially sorted lists. Quicksort Quicksort –O(n.
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.
CSE 373 Data Structures Lecture 15
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
The Lower Bounds of Problems
Analysis of Algorithms CS 477/677
Sorting Conclusions David Kauchak cs302 Spring 2013.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.
Sorting Algorithms Insertion Sort: Θ(n 2 ) Merge Sort:Θ(nlog(n)) Heap Sort:Θ(nlog(n)) We seem to be stuck at Θ(nlog(n)) Hypothesis: Every sorting algorithm.
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,
Heaps and basic data structures David Kauchak cs161 Summer 2009.
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 
Mergeable Heaps David Kauchak cs302 Spring Admin Homework 7?
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.
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
Heapsort CSE 373 Data Structures.
CPSC 411 Design and Analysis of Algorithms
Trees.
CPSC 411 Design and Analysis of Algorithms
Optimal Algorithms Search and Sort.
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.
Ch8: Sorting in Linear Time Ming-Te Chi
Analysis of Algorithms
CSCE 411 Design and 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
Heapsort CSE 373 Data Structures.
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
Lower bound for sorting, radix sort
CPSC 411 Design and Analysis of Algorithms
Chapter 8: Overview Comparison sorts: algorithms that sort sequences by comparing the value of elements Prove that the number of comparison required to.
CS 583 Analysis of Algorithms
Quicksort and Randomized Algs
Algorithms CSCI 235, Spring 2019 Lecture 17 Quick Sort II
Presentation transcript:

David Kauchak cs302 Spring 2012 Sorting Conclusions David Kauchak cs302 Spring 2012

Administrative Assignment 5 out today

Sorting bounds Mergsort is O(n log n) Quicksort is O(n log n) on average Can we do better?

Comparison-based sorting Sorted order is determined based only on a comparison between input elements A[i] < A[j] A[i] > A[j] A[i] = A[j] A[i] ≤ A[j] A[i] ≥ A[j] Do any of the sorting algorithms we’ve looked at use additional information?

Comparison-based sorting Sorted order is determined based only on a comparison between input elements A[i] < A[j] A[i] > A[j] A[i] = A[j] A[i] ≤ A[j] A[i] ≥ A[j] Do any of the sorting algorithms we’ve looked at use additional information? No All the algorithms we’ve seen are comparison-based sorting algorithms

Comparison-based sorting Sorted order is determined based only on a comparison between input elements A[i] < A[j] A[i] > A[j] A[i] = A[j] A[i] ≤ A[j] A[i] ≥ A[j] In Java (and many languages) for a class of objects to be sorted we define a comparator What does it do?

Comparison-based sorting Sorted order is determined based only on a comparison between input elements A[i] < A[j] A[i] > A[j] A[i] = A[j] A[i] ≤ A[j] A[i] ≥ A[j] In Java (and many languages) for a class of objects to be sorted we define a comparator What does it do? Just compares any two elements Useful for comparison-based sorting algorithms

Comparison-based sorting Sorted order is determined based only on a comparison between input elements A[i] < A[j] A[i] > A[j] A[i] = A[j] A[i] ≤ A[j] A[i] ≥ A[j] Can we do better than O(n log n) for comparison based sorting approaches?

Decision-tree model Full binary tree representing the comparisons between elements by a sorting algorithm Internal nodes contain indices to be compared Leaves contain a complete permutation of the input Tracing a path from root to leave gives the correct reordering/permutation of the input for an input 1:3 ≤ > [3, 12, 7] | 1,3,2 | [3, 7, 12] | 1,3,2 | [7, 3, 12] | 2,1,3 | [3, 7, 12]

A decision tree model 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

A decision tree model [12, 7, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3]

A decision tree model [12, 7, 3] Is 12 ≤ 7 or is 12 > 7? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 7 or is 12 > 7?

A decision tree model [12, 7, 3] Is 12 ≤ 3 or is 12 > 3? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 3 or is 12 > 3?

A decision tree model [12, 7, 3] Is 12 ≤ 3 or is 12 > 3? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 3 or is 12 > 3?

A decision tree model [12, 7, 3] Is 12 ≤ 3 or is 12 > 3? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 12 ≤ 3 or is 12 > 3?

A decision tree model [12, 7, 3] Is 7 ≤ 3 or is 7 > 3? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 7 ≤ 3 or is 7 > 3?

A decision tree model [12, 7, 3] Is 7 ≤ 3 or is 7 > 3? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [12, 7, 3] Is 7 ≤ 3 or is 7 > 3?

A decision tree model 3, 2, 1 [12, 7, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| 3, 2, 1 [12, 7, 3]

A decision tree model 3, 2, 1 [3, 7, 12] [12, 7, 3] 1:2 ≤ > 1:3 2:3 |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| 3, 2, 1 [3, 7, 12] [12, 7, 3]

A decision tree model [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

A decision tree model [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

A decision tree model [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

A decision tree model [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

A decision tree model [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [7, 12, 3]

A decision tree model [3, 7, 12] [7, 12, 3] 1:2 ≤ > 1:3 2:3 ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1| [3, 7, 12] [7, 12, 3]

How many leaves are in a decision tree? Leaves must have all possible permutations of the input What if decision tree model didn’t? Input of size n, n! leaves Some input would exist that didn’t have a correct reordering

A lower bound What is the worst-case number of comparisons for a tree? 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

A lower bound The longest path in the tree, i.e. the height 1:2 ≤ > 1:3 2:3 ≤ > ≤ > |2,1,3| 1:3 2:3 |1,2,3| ≤ > ≤ > |1,3,2| |3,1,2| |2,3,1| |3,2,1|

A lower bound What is the maximum number of leaves a binary tree of height h can have? A complete binary tree has 2h leaves log is monotonically increasing from hw 

Can we do better?