Professional Documents
Culture Documents
The Efficiency of Algorithms
The Efficiency of Algorithms
Chapter 9
Chapter Contents
Motivation
Measuring an Algorithm's Efficiency
• Big Oh Notation
Formalities
Picturing Efficiency
The Efficiency of Implementations of the
ADT List
• The Array-Based Implementation
• The Linked Implementation
• Comparing Implementations 2
Motivation
Even a simple program can be noticeably
inefficient
long firstOperand = 7562;
long secondOperand = 423;
long product = 0;
for (; secondOperand > 0; secondOperand--)
product = product + firstOperand;
System.out.println(product);
Analysis of algorithms
• The measuring of the complexity of an
algorithm
Cannot compute actual time for an
algorithm
• We usually measure worst-case time
4
Measuring Algorithm Efficiency
5
Measuring Algorithm Efficiency
8
Big Oh Notation
10
Big Oh Notation
11
Formalities
Formal definition of Big Oh
An algorithm's time requirement f(n) is of
order at most g(n)
• f(n) = O(g(n))
• For a positive real number c and positive
integer N exist such that
12
Formalities
14
Picturing Efficiency
15
Picturing Efficiency
20
Efficiency of Implementations of ADT List
21
Comparing Implementations