Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.

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

Lower Bounds for Sorting, Searching and Selection
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
New discoveries during the exploration of sorting: How I got my thesis topic By Spencer Morgan Reference: Algorithms, Sequential, Parallel, and Distributed.
Sorting Comparison-based algorithm review –You should know most of the algorithms –We will concentrate on their analyses –Special emphasis: Heapsort Lower.
§7 Quicksort -- the fastest known sorting algorithm in practice 1. The Algorithm void Quicksort ( ElementType A[ ], int N ) { if ( N < 2 ) return; pivot.
ADA: 5. Quicksort1 Objective o describe the quicksort algorithm, it's partition function, and analyse its running time under different data conditions.
Lower bound for sorting, radix sort COMP171 Fall 2005.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Competitive Analysis.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Using Divide and Conquer for Sorting
Quicksort Quicksort     29  9.
Quicksort CSE 331 Section 2 James Daly. Review: Merge Sort Basic idea: split the list into two parts, sort both parts, then merge the two lists
Spring 2015 Lecture 5: QuickSort & Selection
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different approaches –Probabilistic analysis of a deterministic algorithm –Randomized.
Analysis of Algorithms
© 2004 Goodrich, Tamassia QuickSort1 Quick-Sort     29  9.
Updated QuickSort Problem From a given set of n integers, find the missing integer from 0 to n using O(n) queries of type: “what is bit[j]
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.
CS 162 Intro to Programming II Quick Sort 1. Quicksort Maybe the most commonly used algorithm Quicksort is also a divide and conquer algorithm Advantage.
© 2004 Goodrich, Tamassia Sorting Lower Bound1. © 2004 Goodrich, Tamassia Sorting Lower Bound2 Comparison-Based Sorting (§ 10.3) Many sorting algorithms.
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different but similar analyses –Probabilistic analysis of a deterministic algorithm.
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.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Amortized Analysis Some of these lecture slides are adapted from CLRS.
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.
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.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
S: Application of quicksort on an array of ints: partitioning.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
The Complexity of Algorithms and the Lower Bounds of Problems
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
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
10 Algorithms in 20th Century Science, Vol. 287, No. 5454, p. 799, February 2000 Computing in Science & Engineering, January/February : The Metropolis.
Sorting and Lower bounds Fundamental Data Structures and Algorithms Ananda Guna January 27, 2005.
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.
Sorting Algorithms 2. Quicksort General Quicksort Algorithm: Select an element from the array to be the pivot Select an element from the array to be the.
Analysis of Algorithms CS 477/677
CSC 213 Lecture 13: Writing Code & Sorting Lowest Bound.
Randomized Algorithms CSc 4520/6520 Design & Analysis of Algorithms Fall 2013 Slides adopted from Dmitri Kaznachey, George Mason University and Maciej.
1 Lower Bound on Comparison-based Search We have now covered lots of searching methods –Contiguous Data (Arrays) Sequential search Binary Search –Dynamic.
Instructor Neelima Gupta Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
Sorting 1. Insertion Sort
Data Structures Haim Kaplan & Uri Zwick December 2013 Sorting 1.
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 
CSE 326: Data Structures Lecture 23 Spring Quarter 2001 Sorting, Part 1 David Kaplan
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.
CSC317 1 Hiring problem-review Cost to interview (low C i ) Cost to fire/hire … (expensive C h ) n number of candidates m hired O (c i n + c h m) Independent.
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 Chapter 7 Quicksort. 2 About this lecture Introduce Quicksort Running time of Quicksort – Worst-Case – Average-Case.
David Kauchak cs062 Spring 2010
Sorting Lower Bound 4/25/2018 8:49 PM
CPSC 411 Design and Analysis of Algorithms
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Sorting We have actually seen already two efficient ways to sort:
(2,4) Trees 12/4/2018 1:20 PM Sorting Lower Bound Sorting Lower Bound.
CS200: Algorithm Analysis
CS 3343: Analysis of Algorithms
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
David Kauchak cs302 Spring 2012
The Selection Problem.
Algorithms CSCI 235, Spring 2019 Lecture 17 Quick Sort II
Presentation transcript:

Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis

2 Beyond Worst Case Analysis Worst-case analysis. n Analyze running time as function of worst input of a given size. Average case analysis. n Analyze average running time over some distribution of inputs. n Ex: quicksort. Amortized analysis. n Worst-case bound on sequence of operations. n Ex: splay trees, union-find. Competitive analysis. n Make quantitative statements about online algorithms. n Ex: paging, load balancing.

3 Average Case Analysis Average case analysis. n Analyze average running time over some distribution of inputs. n Ex: quicksort. – O(N log N) if input is assumed to be in random order. – leads to randomized algorithm with O(N log N) expected running time, independent of input n Major disadvantage: hard to quantify what input distributions will look like in practice.

4 Quicksort Quicksort. n Assume all elements are unique. n Assume input is a random permutation of inputs. n Denote i th largest element by i. void quicksort(Item a[], int left, int right) { int m; if (right > left) { m = partition(a, left, right); quicksort(a, left, m - 1); quicksort(a, m + 1, right); } quicksort.c

5 Quicksort: BST Representation of Pivots 10 pivot elements

6 Probability that i = 2 and j = 7 get compared. n Let x be pivot element that separates i and j. n Case 1: x  {3, 4, 5, 6}  i and j not compared. Quicksort: Average Case Analysis

7 Probability that i = 2 and j = 7 get compared. n Let x be pivot element that separates i and j. n Case 1: x  {3, 4, 5, 6}  i and j not compared. n Case 2: x  {2, 7}  i and j are compared. Quicksort: Average Case Analysis

8 Probability that i = 2 and j = 7 get compared. n Let x be pivot element that separates i and j. n Case 1: x  {3, 4, 5, 6}  i and j not compared. n Case 2: x  {2, 7}  i and j are compared. Quicksort: Average Case Analysis

9 Quicksort: average case analysis. n Expected # of comparisons = Remark: same analysis if we choose partition element uniformly at random. n Running time independent of input. Quicksort: Average Case Analysis

10 Comparison Based Sorting Lower Bound a1 < a2 a1 < a3 a2 < a3 a1 < a3 a2 < a32, 1, 3 2, 3, 13, 2, 11, 3, 23, 1, 2 1, 2, 3 YES NO Decision Tree of Program

11 Comparison Based Sorting Lower Bound Lower bound =  (N log 2 N): applies to comparison-based algorithms. n Tree height h determines worst case running time. n N! different input orderings. n One (or more) leaves corresponds to each ordering. n Binary tree with N! leaves has height: Stirling's formula