Академический Документы
Профессиональный Документы
Культура Документы
Lecture 2
Slide 1 of 66.
Asymptotic Analysis
How running time off an algorithm increases when input
Lecture 2
Slide 2 of 66.
Lecture 2
Slide 3 of 66.
Lecture 2
Slide 4 of 66.
Lecture 2
Slide 5 of 66.
Example
We will show that
Lecture 2
Slide 6 of 66.
or a constant function
Lecture 2
Slide 7 of 66.
Lecture 2
Slide 8 of 66.
is a subset of
Lecture 2
Slide 9 of 66.
Lecture 2
Slide 10 of 66.
Lecture 2
Slide 11 of 66.
O notation
Running time of an algorithm can be found by inspecting
complexity
Lecture 2
Slide 12 of 66.
Lecture 2
Slide 13 of 66.
Bubble sort
Lecture 2
Slide 14 of 66.
Horners Rule
Lecture 2
Slide 15 of 66.
Lecture 2
Slide 16 of 66.
Theorem
Lecture 2
Slide 17 of 66.
Lecture 2
Slide 18 of 66.
Lecture 2
Slide 19 of 66.
Monotonocity
Lecture 2
Slide 20 of 66.
Lecture 2
Slide 21 of 66.
Lecture 2
Slide 22 of 66.
Quicksort
Given A[pr], pick any element A[q] as the pivot.
Partition A[pr] into sub-arrays
A[p (q 1)]
A[(q + 1) r]
Lecture 2
Slide 23 of 66.
Algorithm
Quicksort(A, p, r)
if p < r
q = partition(A,p,r)
Quicksort(A,p,q-1)
Quicksort(A,q+1, r)
Lecture 2
Slide 24 of 66.
Lecture 2
Slide 25 of 66.
Lecture 2
Slide 26 of 66.
Lecture 2
Slide 27 of 66.
Lecture 2
Slide 28 of 66.
Lecture 2
Slide 29 of 66.
Lecture 2
Slide 30 of 66.
Loop invariants
Can be proved by induction
They help in understanding the algorithm
Lecture 2
Slide 31 of 66.
Complexity
Lecture 2
Slide 32 of 66.
side is empty.
T(n) for an empty array is T(0)
Lecture 2
Slide 33 of 66.
Lecture 2
Slide 34 of 66.
9/10
Lecture 2
Slide 35 of 66.
Lecture 2
Slide 36 of 66.
Lecture 2
Slide 37 of 66.
Quicksort
Worst case hardly occurs in practice
Even if the array splits to n/100 & 99n/100, complexity
remains at
Lecture 2
Slide 38 of 66.
Quicksort
Worst case hardly occurs in practice
Lecture 2
Slide 39 of 66.
Quicksort
Widely used in practice
Performs better than Merge-sort
In average case both are
But Quicksort has smaller const of proportionality
Also In-PLACE update: no extra memory
Lecture 2
Slide 40 of 66.
Quicksort
Donald Knuth
Edsger Dijkstra
Niklaus Wirth
Dana Scott
Raj Reddy
Lecture 2
Slide 41 of 66.