

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


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.^ 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 runningtime, independent of input n^
Major disadvantage: hard to quantify what input distributions willlook like in practice.
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
pivot elements
Probability that i = 2 and j = 7 get compared.^ n
Let x be pivot element that separates i and j. n^
Case 1: x
i and j not compared.
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
i and j not compared.
n^
Case 2: x
i and j are compared.
Probability that i = 2 and j = 7 get compared.^ n
Let x be pivot element that separates i and j. n^
Case 1: x
i and j not compared.
n^
Case 2: x
i and j are compared.
compared
and Pr[
i j
)j i(
j
i