415 lecture note #5 


[Ch 3] Algorithms (3)

3.5 Complexity of Algorithms

0. Overview

1. Number of times a line is executed

2. Logarithmic Growth

iteration value of  i
(at the top of loop)
number of times
line 4 is executed
1 n 1
2 n/21 1
3 n/22 1
k n/2k-1 = 1 1
k+1 n/2k = 0 0
(loop not executed)

We are interested in what k is (because that's the number of times the line 4 is executed).  In other words,

T(n) = 1 + 1 + 1 + .. + 1  = (k * 1)
          |<-- k of them--->|

To derive k, we look at the relation at the last iteration (kth):



So, T(n) = log2n + 1   (where log2n is alternatively written as lgn).

3. Various Asymptotic Growth Functions

4. Big-Oh (O), Omega (W) and Theta (Q) Notations

NOTE:  Any function of the form nk is called a polynomial of degree k.

 

NOTE:  Throughout the rest of this document, n is a positive integer (i.e., n >= 1).

(1) Big-Oh

(2) Omega

 

 

 

 

 

 

 

 

(3) Theta