FIND_MAX_MIN_AVERAGE(A)
- min ← ∞
- max ← -∞
- sum ← 0
- count ← 0
- for i ← 0 to A.size()-1 do
- sum ← sum + A[i]
- if A[i] > max then
- max ← A[i]
- if A[i] < min then
- min ← A[i]
- average ← sum / n
- return max, min, average
t1(n) ∈ O(g1(n)) means
there exists c1 and n1 such that
0 < t1(n) ≤ c1 g1(n) for n > n1
t2(n) ∈ O(g2(n)) means
there exists c2 and n2 such that
0 < t2(n) ≤ c2 g2(n) for n > n2
let n3 = max(n1, n2)
let c3 = max(c1, c2)
So
t1(n) + t2(n) ≤ c1 g1(n) + c2 g2(n)
≤ c3 g1(n) + c3 g2(n)
≤ c3( g1(n) + g2(n))
≤ c3*2* max( g1(n) , g2(n))
COMPLEX_ALGORITHM
- execute some algorithm with time T1(n)
- execute some algorithm with time T2(n)
f(n) | 0 then t(n) has a smaller order of growth than g(n)
limn→ ∞ ---- = | c then t(n) and g(n) have the same order of growth
g(n) | &inifn; then t(n) has a larger order of growth than g(n)