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

How can I do graphics in c?

0 Answers  


please send me the code for multiplying sparse matrix using c

0 Answers  


What is the acronym for ansi?

0 Answers  


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

0 Answers  


Explain what are the standard predefined macros?

0 Answers  






What functions are used for dynamic memory allocation in c language?

0 Answers  


1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1 Answers  


What language is c written?

0 Answers  


I didn't count the ducks that I saw in line, but I do remember that one duck was in front of two ducks, another duck behind two ducks. How many ducks did I see?

2 Answers  


What is the use of printf() and scanf() functions?

0 Answers  


What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;

12 Answers   TCS,


How to delete a node from linked list w/o using collectons?

0 Answers   Zycus Infotech,


Categories