Advance Algorithm Introduction
Advance Algorithm Introduction
Reference Books:
• 1. Rajeev Motwani, Prabhakar Raghavan, Randomized Algorithm, Cambridge University
Asymptotic Notations
The Role of Algorithms in Computing
• Analysis:
• Sequence of computational steps that transform the
• input into the output
• Predict the cost of an algorithm in terms of resources and
performance
• Tool for solving a well-specified computational problem
key
sorted
What kinds of problems are solved by algorithms?
• Sorting is by no means the only computational problem for
which algorithms have been developed.
• Ex.
1. Finding good routes on which the data will travel
2. Using a search engine to quickly find pages on which particular
information resides
3. Human Genome Project has made great progress toward the goals of
identifying all the 100,000 genes in human DNA, determining the
sequences of the 3 billion chemical base pairs that make up human
DNA, storing this information in databases, and developing tools for
data analysis. Each of these steps requires sophisticated algorithms.
Analyzing Algorithms
L1.14
Running time
L1.16
Complexity Analysis using RAM model
L1.17
Complexity Analysis using RAM model
L1.18
Kinds of analyses
Worst-case: (usually)
• T(n) = maximum time of algorithm on any input of size n.
Average-case: (sometimes)
• T(n) = expected time of algorithm over all inputs of size n.
• Need assumption of statistical distribution of inputs.
Best-case: (NEVER)
• Cheat with a slow algorithm that works fast on some input.
Machine-independent time
“Asymptotic Analysis”
Q-notation
DEF:
Q(g(n)) = { f (n) : there exist positive constants c1, c2, and n0 such that
0 c1 g(n) f (n) c2 g(n) for all n n0 }
if f(n) is theta of g(n), then the value f(n) is always between c1 * g(n) and c2 *
g(n) for large values of n (n ≥ n0)
• Basic manipulations:
• Drop low-order terms; ignore leading constants.
• Example: 3n3 + 90n2 – 5n + 6046 = Q(n3)
Asymptotic performance
When n gets large enough, a Q(n2) algorithm always beats a Q(n3) algorithm.
n n0
Relations Between Q, O, W
Amortized Analysis
Amortized Analysis
Amortized Analysis