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

What is openmp in c?

0 Answers  


which types of data structure will i use to convert infix to post fix???

5 Answers   IIT,


WRITE A PROGRAM TO FIND A REVERSE OF TWO NO

7 Answers  


Is c is a low level language?

0 Answers  


Is main is user defined function?

0 Answers  


Why pointers are used?

0 Answers  


write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?

4 Answers  


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

0 Answers   TCS,


Write a C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes. If an intrusion attempt is detected beep the internal speaker to alert the administrator. A high number of aborted connects to MySQL at a point in time may be used as a basis of an intrusion.

2 Answers   Drona Solutions, Infosys, Vodafone, Webyog,


int main() { Int n=20,i; For(i=0;i<=n;i--) { Printf(“-“); Return 0;

0 Answers  


Is c procedural or functional?

0 Answers  


Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.

8 Answers  


Categories