1 Analysis of Algorithms
ANALYSIS OF ALGORITHMS
- Quick Mathematical Review
- Running Time
- Pseudo-Code
- Analysis of Algorithms
- Asymptotic Notation
- Asymptotic Analysis
A Quick Math Review Logarithms and Exponents - properties of - - PDF document
A NALYSIS OF A LGORITHMS Quick Mathematical Review Running Time Pseudo-Code Analysis of Algorithms Asymptotic Notation Asymptotic Analysis T(n) n = 4 Input Algorithm Output Analysis of Algorithms 1 A Quick Math
1 Analysis of Algorithms
2 Analysis of Algorithms
logab c*logab
3 Analysis of Algorithms
i s = t
=
1 +
i = n
4 Analysis of Algorithms
Input Instance Running Time
1 ms 2 ms 3 ms 4 ms 5 ms A B C D E F G
worst-case best-case
average-case
5 Analysis of Algorithms
50 100
t (ms) n
10 20 30 40 50 60
6 Analysis of Algorithms
7 Analysis of Algorithms
Algorithm arrayMax(A, n): Input: An array A storing n integers. Output: The maximum element in A. currentMax ← A[0] for i ← 1 to n −1 do if currentMax < A[i] then currentMax ← A[i] return currentMax
8 Analysis of Algorithms
if ... then ... [else ... ]
while ... do
repeat ... until ...
for ... do
A[i]
return value
9 Analysis of Algorithms
i 1 2 3 … n + + + + =
i 1 = n
n2 n + 2
1 n/2 1 2 n 3 2 n+1 ... 1 2 n 1 2 n 3 3 ...
10 Analysis of Algorithms
Algorithm arrayMax(A, n): Input: An array A storing n integers. Output: The maximum element in A. currentMax ← A[0] for i ← 1 to n −1 do if currentMax < A[i] then currentMax ← A[i] return currentMax
11 Analysis of Algorithms
Input Size Running Time cg(n) f(n) n0
12 Analysis of Algorithms
13 Analysis of Algorithms
14 Analysis of Algorithms
Algorithm prefixAverages1(X): Input: An n-element array X of numbers. Output: An n-element array A of numbers such that A[i] is the average of elements X[0], ... , X[i]. Let A be an array of n numbers. for i ← 0 to n - 1 do a ← 0 for j ← 0 to i do a ← a + X[j] A[i] ← a/(i + 1) return array A
15 Analysis of Algorithms
Algorithm prefixAverages2(X): Input: An n-element array X of numbers. Output: An n-element array A of numbers such that A[i] is the average of elements X[0], ... , X[i]. Let A be an array of n numbers. s ← 0 for i ← 0 to n - 1 do s ← s + X[i] A[i] ← s/(i + 1) return array A
16 Analysis of Algorithms
17 Analysis of Algorithms