Professional Documents
Culture Documents
Analysis of Algorithms
By:
Mr. Waqas Haider Khan Bangyal
Class Policy
Homework Assignments:
5%
Class Participation & Programming Project:
10 %
Quizzes:
5%
Midterm :
30% Introduction to Algorithms
Final Exam : Thomas H. Cormen,
50% Charles E. Leiserson,
Late homework Ronald L. Rivest and
Submit a HARDCOPY before the class. Clifford Stein
No late submissions
Pre Req
Data Structures
C++
Discrete Mathematics
Basic Math skills
Lots of Time…
What can you expect?
After the course expect to
Know more about algorithms (of course)
Think algorithmically
Know how to solve real world algorithmic
problems
Both in theory (algorithm) and practice
(code)
Be better at applications that require algorithms:
and apply algorithms to places you never
imagined…
Expectations
Work hard and learn/understand the material well.
Feel free to ask questions.
Take help from me
Course Load: 4-6 hours a week (assumes you are
getting help).
Why Study Algorithms?
Necessary in any computer programming problem
Improve algorithm efficiency: run faster, process more data, do
something that would otherwise be impossible
Solve problems of significantly large sizes
Technology only improves things by a constant factor
Compare algorithms
Algorithms as a field of study
Learn about a standard set of algorithms
New discoveries arise
Numerous application areas
2 106 instructions
2
Your friend = 2000seconds
9
10 instructions / second
You = 50 106 lg106 instructions
7
100seconds
10 instructions / second
20 times better!!
Algorithm Analysis: Example
Alg.: MIN (a[1], …, a[n])
m ← a[1];
for i ← 2 to n
if a[i] < m
then m ← a[i];
Running time:
the number of primitive operations (steps) executed
before termination
T(n) =1 [first step] + (n) [for loop] + (n-1) [if condition] +
(n-1) [the assignment in then] = 3n - 1
Order (rate) of growth:
The leading term of the formula
Expresses the asymptotic behavior of the algorithm
Typical Running Time Functions
1 (constant running time):
Instructions are executed once or a few times
logN (logarithmic)
A big problem is solved by cutting the original problem in smaller sizes,
N logN
A problem is solved by dividing it into smaller problems, solving them
nested loops)
N3 (cubic)
Processing of triples of data (triple nested loops)
NK (polynomial)
2N (exponential)
Few exponential algorithms are appropriate for practical use
Why Faster Algorithms?
Asymptotic Notations
A way to describe behavior of functions in the limit
Abstracts away low-order terms and constant factors
O notation:
asymptotic “less than and equal”: f(n) “≤” g(n)
notation:
asymptotic “greater than and equal”:f(n) “≥” g(n)
notation:
asymptotic “equality”: f(n) “=” g(n)
Recursive Algorithms
Binary search: for an ordered array A, finds if x is in the array A[lo…
hi]
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A