Fundamental Analysis of Algorithm
Fundamental Analysis of Algorithm
Analysis of Algorithm
Efficiency
0750323 ALGORITHMS
DR. RANEEM QADDOURA
Approaches:
◦ Theoretical analysis
◦ Empirical analysis
T(n) ≈ copC(n)
running time execution time Number of times
for basic operation basic operation is
or cost executed
Note: Different basic operations may cost differently!
Example:
◦ How much faster will algorithm run on computer that is twice as fast?
◦ How much longer does it take to solve problem of double input size?
• Average case:
• K is in A => (n+1)/2 key comparisons
• K is not in A => n key comparisons
•If f (n) O(g (n)) and g(n) O(h(n)) , then f(n) O(h(n))
• For example, 𝑛 O(𝑛2 ) and 𝑛2 O(𝑛3 ) and 𝑛 O(𝑛3 )
•If f1(n) O(g1(n)) and f2(n) O(g2(n)) , then f1(n) + f2(n) O(max{g1(n), g2(n)})
◦ True for the -notation and -notation.
◦ Implication: The algorithm’s overall efficiency will be determined by the part with a larger order of
growth, i.e., its least efficient part.
◦ For example, 5𝑛2 + 3𝑛 O(𝑛2 ) why?
◦ 5𝑛2 O(𝑛2 ) and 3𝑛 O(𝑛) then 5𝑛2 + 3𝑛 O{max {𝑛, 𝑛2 }} which is 5𝑛2 + 3𝑛 O(𝑛2 )