CEN 235 1. Algorithm Analysis
CEN 235 1. Algorithm Analysis
1. Algorithm Analysis
▪ Algorithm
▪ Algorithm Analysis
▪ Asymptotic Notations
▪ O (Big-Oh) Notation
▪ Rules for Algorithm Analysis
▪ Examples
Algorithm
▪ What is an algorithm?
Algorithm
▪ Execution time may be found for a given algorithm using some special
performance programs called benchmarks.
▪ Second alternative for performance assessment is to find the growth rate of
the execution time or the memory space need of an algorithm with the
growing input size.
▪ Here, we define the execution time or the memory space used as a function
of the input size such as the number of elements in an array, the number of
records in a file etc.
What to Analyse
▪ The other main factors are the algorithm used and the input to the algorithm.
▪ Typically, the size of the input is the main consideration.
▪ We usually use N to denote the size of the input.
▪ Number of elements in an array, etc.
▪ The running time of a for loop is at most the running time of the
statements inside the for loop (including tests) times the number
of iterations.
Rule 2: Nested for Loops
▪ These just add (which means that the maximum is the one that
counts).
▪ As an example, the following program fragment, which has O(N)
work followed by O(N2) work, is also O(N2) :
Rule 4: if/else