You are on page 1of 1

Big O (Just O)= upper bound n2 -> n3 -> n4

Theta ( O with line)= tight bound = n2 -> 2n2 -> 3n2


Omega (GoF symbol hehe) = lower bound = n2 -> n1 -> n0 -> n-1

Finding the value of f(n) to get big O

Ex. linearequation
for (i = 0,sum=0; i < n; i++)
sum += a[i];

Solution:
Step 1: f(n)= 2+ ---> Count how many initializations are there in the code
Step 2: f(n)= 2+ n ---> How many times do we proccess the loop (its the i<n) always put n
Step 3: f(n)= 2+ 2n ---> (altering) what changes if n changes (sum and i) then put it before n
Step 4: O(n) ---> Find Big 0 (2n but remove 2)

1. Constant
2. Logarithmic equation = single loop with the process inside * or /
(radics is dependent on what multiplies/divides it)
3. Linear equation = single loop with the process inside + or -
4. Linearithmic = Nested loop where the inner most loop is a * or / (outerloop)x(inneloop)
First loop does not includes secondloop for the declaration
Logarithmic is not included in the alterings

Second loop does includes first loop for the declaration


Logarithmic in the alterings changes the n to log(radic)n (logarithmic)
Then multply both sides

5. Quadratic = Nested loop with + or - processes


Quadratic dependent =f(n)= ()+() (n-1) = if the inner looping process depends on the
number of the outer loop (second loop does not need step 1)

Quadratic independent =f(n)= ()*() =


First loop does not includes secondloop for the declaration
First loop altering includethe second loop

Second loop does includes first loop for the declaration


Second loop altering does not inclue the first loop

6. Cubic = 3 loops
First loop does not includes secondloop for the declaration
First loop altering includethe second loop

Second loop does includes first loop for the declaration


Second loop altering does not inclue the first loop

7. Exponential
8. Factorial

You might also like