Professional Documents
Culture Documents
Algorithmic Time Complexity Analysis
Algorithmic Time Complexity Analysis
Bog-O Notation
describes an algorithm that will always execute in the same time (or space)
regardless of the size of the input data set
O(N)
denotes an algorithm that will continue to halve the data set with each
iteration until the value has been found or until it can no longer split
the data set.
int addNumber()
{
int a = 5; 1 Unit of time for every operation.
int b = 6; Operation such as arithmetic, relational
int sum; logical or assignment operation.
sum = a+b; Let T be the algorithm
return sum; O(T) = 4
}
Calculate the function time of the given algorithm using O-notation (2)
int addNumber()
{
int a = 5; Ignore the lower order terms.
int b = 6; Ignore the constant multiplier.
int sum;
sum = a+b; Let T be the algorithm
return sum; O(T) = 4
} O(T) = O(1)
Calculate the function time of the given algorithm using O-notation (3)
int n = 5;
int sum = 0;
for(int i = 1; i<=n;i++)
{
sum+=i;
}
Calculate the function time of the given algorithm using O-notation (4)
int n = 5;
int sum = 0;
int n = 5;