









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!










Outline
Announcements:
Last time:
Today:
Algorithm Design
Typical approach:
Creative refinements:
Example of Exploiting Characteristics: Bubble Sort v.
Sort array a[20,30,15,10,35,25] by “bubbling” the largest element to the right
Stop program as soon as array is sorted (How do you know that the array is sorted?)
How many CMPs does it take in the worst case?
Taking Advantage of Workload Characteristics
What if array is already sorted initially?
Implication: performance of a given alg. depends on the characteristics of the offered workload (initial values, input)
Conversely, depending on the expected workload, some algorithm/data structure may be more suitable than others
Don’t Lose the Forest...
Operations useful in maintaining an address book:
How do you do insertion and deletion on an array?
How much does each operation cost, on average, for sorted and unsorted array?
Which algorithm to use (shall we keep the array sorted)?
The Language of Algorithm Analysis
How do you convince your boss that your solution is better than an existing solution?
Big-Oh: Example
Algorithm A has time complexity f (n) = 8n + 128 Algorithm B has time complexity g(n) = n^2
Can we say that f (n) = O(g(n))? Is 8 n + 128 ≤ c · n^2?
Let c = 1, clearly for n = 8, f (n) > g(n). At what value of no is g(n) > f (n), ∀n ≥ no? How about if c = 2 or c = 4? See Fig. 3.1.
Big-Oh: Summary
As long as there is a c > 0 , and an no ≥ 0 , such that c · g(n) ≥ f (n), for all n ≥ no, you can say f (n) = O(g(n)). In this case, 8 n + 128 = O(n^2 ).
In other words, we only care about LARGE n, it doesn’t matter what c is.
Also, asymptotically, n^2 + k = O(n^2 ), why?
(Obviously, c cannot be 10100 (one googol , the conjectured upper bound on the number of atoms in the observable universe)!)
The Common Case: Empirical Performance
What if no > average n or common case n?
To determine the common case performance, given known workload, run empirical peformance measurement.
Note that common case performance is not necessary average case performance. (Why not?)
Pay attention to:
Experiment Setup
Factors involved in running an empirical performance study: