T(n) = Σi=0n-2 Σj=i+1 n-1 1 = Σi=0n-2 n-1 - (i+1) + 1 = Σi=0n-2 n-i-1 = Σi=0n-2 n - 1 Σi=0n-2 i = (n-1) Σi=0n-2 1 - (n-2)(n-1)/2 = (n-1) (n-2 -0+1) - (n-2)(n-1)/2 = (n-1)[(n-1) -(n-2)/2] = (n-1)[n-1/2n -1+1] = (n-1)(1/2n) = (n-1)(n)/2 = 1/2 n2 - 1/2 n ∈ O(n2)
T(n) = n-1 + n-2 + n-3 + ... + 2 + 1 = $Sigma;i=1n-1 i = (n-1)(n)/2
MATRIX_MULTIPLY(A,B) // both are nxn
- 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
T(n) = Σ0n-1 Σ0n-1 Σ0n-1 1 = Σ0n-1 Σ0n-1 n = Σ0n-1 n Σ0n-1 1 = Σ0n-1 n2 = n2 Σ0>n-1 1 = n3