how to calculate the time complexity of a given algorithm?
pls give exaples..mainly for the coplexities such as O(log
n),O(n log n)...



how to calculate the time complexity of a given algorithm? pls give exaples..mainly for the coplexi..

Answer / s v s pradeep

Generally 0(log n) and 0(n log(n)) will come into picture
if u are dealing with the programs that have for loops
(where the increment is divided or multiplied), functional
blocks.

Eg. for(i=0;i<n;i=i++)
for(j=0;j<n;j=j*2)
......
Here in this case the inner loop complexity is 3n+2 where
the outer loop complexity will be in logarithm terms
because every time when we increment i value the, i is
multiplied by 2 so the no of iterations will be reduced ..
so when the iterations are reduced then we will get log(n)


so, for the above example the complexity will be 0(n log(n))
n-- for the outer loop and log(n) is for inner loop.

so multiply the no of times innerloop will be executed for
the outer loop. so n*log(n).
So the time complexity will be 0(n log(n)).

..

Is This Answer Correct ?    14 Yes 7 No

Post New Answer

More C Interview Questions

Calculate 1*2*3*____*n using recursive function??

0 Answers  


Explain what are the different file extensions involved when programming in c?

0 Answers  


what is c language?

2 Answers  


when i declare as: void main() { clrscr(); int a=10; printf("%d",a) } my problem that why generate a error in above programs. please tell me answer seriously .

4 Answers  


can we declare a variable in different scopes with different data types? answer in detail

3 Answers   TCS,






. Consider the following program main() { int a[5]={1,3,6,7,0}; int *b; b=&a[2]; } The value of b[-1] is (A) 1 (B) 3 (C) -6 (D) none

9 Answers   Oracle,


Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???

2 Answers   TCS,


What is self-referential structure in c programming?

0 Answers  


What is formal argument?

0 Answers  


Write a program to compute the following 1!+2!+...n!

4 Answers  


Explain the difference between strcpy() and memcpy() function?

0 Answers  


what is C?

9 Answers   Syntel,


Categories