Algorithm Analysis
Algorithm Analysis
Algorithm Analysis
Lectures 3 & 4
Resources
Data Structures & Algorithms Analysis in C++
(MAW): Chap. 2
Introduction to Algorithms (Cormen, Leiserson, &
Rivest): Chap.1
Algorithms Theory & Practice (Brassard & Bratley):
Chap. 1
Algorithms
• An algorithm is a well-defined
computational procedure that takes
some value or a set of values, as input
and produces some value, or a set of
values as output.
• Or, an algorithm is a well-specified set
of instructions to be solve a problem.
Efficiency of Algorithms
• Empirical
– Programming competing algorithms and
trying them on different instances
• Theoretical
– Determining mathematically the quantity of
resources (execution time, memory space,
etc) needed by each algorithm
Analyzing Algorithms
• Predicting the resources that the algorithm
requires:
• Computational running time
• Memory usage
• Communication bandwidth
• The running time of an algorithm
• Number of primitive operations on a particular input size
• Depends on
– Input size (e.g. 60 elements vs. 70000)
– The input itself ( partially sorted input for a sorting
algorithm)
Order of Growth
• The order (rate) of growth of a running
time
– Ignore machine dependant constants
– Look at growth of T(n) as n→∞
Θ notation
• Drop low-order terms
• Ignore leading constants
• E.g.
– 3n3 + 90n2 – 2n +5 = Θ (n3)
Mathematical Background
Mathematical Background
• Definitions:
– T(N) = O(f(N)) iff ∃ c and n0 ∋
T(N) ≤ c.f(N) when N ≥ n0
– T(N) = Ω (g(N)) iff ∃ c and n0 ∋
T(N) ≥ c.g(N) when N ≥ n0
– T(N) = Θ (h(N)) iff T(N) = O(h(N)) and
T(N) = Ω (h(N))
Mathematical Background
• Definitions:
– T(N) = o(f(N)) iff ∃ c and n0 ∋
T(N) < c.f(N) when N ≥ n0