






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to algorithm analysis, focusing on the asymptotic notation and complexity of algorithms. It covers various functions, their growth rates, and the properties of transitivity and additivity. The document also includes examples and comparisons of different functions, such as logarithmic, polynomial, exponential, and factorial. It is a valuable resource for computer science students and professionals seeking to understand the performance characteristics of algorithms.
Typology: Lecture notes
1 / 38
This page cannot be seen from the preview
Don't miss anything!































› Stable matching problem.
› Gale-Shapley algorithm
› Question: For a given problem instance, there may be several stable matchings. Do all executions of Gale-Shapley yield the same stable matching? If so, which one?
› An instance with two stable matchings.
Zeus
Yancey
Xavier
A
B
A
1 st
B
A
B
2 nd
C
C
C
3 rd
Clare
Bertha
Amy
X
X
Y
1 st
Y
Y
X
2 nd
Z
Z
Z
3 rd
"For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious. But once unlocked, they cast a brilliant new light on some aspect of computing." - Francis Sullivan
A tractable problem is one that can be solved in a reasonable amount
of time; usually the distinction between tractable and intractable is
drawn at the boundary between problems that can be solved in an
amount of time that is polynomial ; those that require exponential time
are regarded as intractable.
There are two aspects of algorithmic performance:
› Time
› Instructions take time. › How fast does the algorithm perform? › What affects its runtime?
› Space
› Data structures take space › What kind of data structures can be used? › How does choice of data structure affect the runtime?
We will focus on time:
› How to estimate the time required for an algorithm
› How to reduce the time required
› Worst-Case Analysis › The maximum amount of time that an algorithm require to solve a problem of size n. › This gives an upper bound for the time complexity of an algorithm. › Normally, we try to find worst-case behavior of an algorithm. › Best-Case Analysis › The minimum amount of time that an algorithm require to solve a problem of size n. › The best case behavior of an algorithm is NOT so useful. › Average-Case Analysis › The average amount of time that an algorithm require to solve a problem of size n. › Sometimes, it is difficult to find the average-case behavior of an algorithm. W orst-case analysis is more common than average-case analysis.
How many steps are taken in the execution of these codes?
if(x < y) { int temp = x; x = y; y = temp; }
It depends (more if x<y, less otherwise)! The worst case (when x<y): Num of steps = 1 + 1 + 1 + 1 = 4
How many steps are taken in the execution of this loop?
for (i = 0; i < 10 ; i++) { ar[i] = i; }
1 10 + 1
1 10
1 10
Number of steps = 1 + (1 ⋅ 10 + 1) + (1 ⋅ 10) + (1 ⋅ 10) = 32
1
› Worst case running time. Obtain bound on largest possible running time of algorithm on input of a given size N.
› Average case running time. Obtain bound on running time of algorithm on random input as a function of input size N.
› Definition: An algorithm is efficient if its running time is polynomial.
› Justification: It really works in practice!
› Exceptions.
Unix grep