MAX_ELEMENT(A)
- maxval ← A[0]
- for i ← 1 to n-1 do
- if A[i] > maxval
- maxval ← A[i]
- return maxval
UNIQUE_ELEMENTS(A)
- for i ← 0 to n-2 do
- for j ← i+1 to n-1 do
- if A[i] = A[j]
- return false
- return true
g(i) = 1 Σj=i+1n-1 1 = n-1-(i+1) + 1 = n-i-1 Σi=0n-2 (n-i-1) = Σi=0n-2 (n-1) - Σi=0n-2 i = (n-1) Σi=0n-2 1 - Σi=0n-2 i = (n-1) (n-2 -0 + 1 ) + (n-2)(n-1) * 1/2 = (n-1)(n-1) - (n-2)(n-1)/2 = (n-1)/2 [2(n-1)- (n-2)] = (n-1)/2 [2n -n -2 +2] = (n-1)/2 [n] ∈ Θ(n2)
BIG_POWER(A)
- for i ← 0 to n-1 do
- A[i] ← power(A[i], 100,000)
- return
MATRIX_MULTIPLY(A,B)
- for i ← 0 to n-1 do
- for j ← 0 to n-1 do
- C[i,j] ← 0
- for k ← 0 to n-1 do
- C[[i,j] ← C[i,j] + A[i,k] * B[k,j]
- return C
POWER(x,n)
- result ← 1
- while n > 0 do
- if n % 2 != 0
- result ← result * x
- x ← x * x
- n ← n / 2
- return result