Algorithm Note 2
Algorithm Note 2
Algorithm:
Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output. Algorithms are generally
created independent of underlying languages, i.e. an algorithm can be
implemented in more than one programming language.
Functional Diagram:
Problem
Algorithm
m
8.i) Big O Notation/Big Oh Notation :Big-Oh (O) notation gives an upper bound for
a function f(n) to within a constant factor.
O( 3n3 + 2n + 7 )
1)after removing contestant term 7 we get O(3n3 + 2n )
2) after removing lower order term 2n we get O(3n3 )
3) after removing constant term of higher order we get O(n3 )
Example2: Calculate the Big O where f(n)=2n+1
f(n)=2n+1= 2.2n for all n>=0 So f(n)=O(2n)
Example3: Calculate the Big O where f(n)=n!
f(n)=n!= n*(n-1)*(n-2)*(n-3)*…………3*2*1
< n*n*n*n………..*n*n*n for all n>0
=nn
f(n)=O(nn)
Example4: Calculate the Big O where f(n)=10nlogn+5n4+7*2n
n nlogn n4 2n
1 0 1 2
2 .61 16 4
3 1.43 81 8
4 2.40 256 16