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 manipulate individual bits?

0 Answers  


How can I manipulate strings of multibyte characters?

0 Answers  


How to swap two values using a single variable ? condition: Not to use Array and Pointer ?

6 Answers  


What are the 3 types of structures?

0 Answers  


what is the difference between these initializations? Char a[]=”string”; Char *p=”literal”; Does *p++ increment p, or what it points to?

4 Answers  






Describe explain how arrays can be passed to a user defined function

0 Answers  


In c language can we compile a program without main() function?

0 Answers  


. A database table called PERSON contains the fields NAME, BASIC and HRA. Write a computer program to print a report which employee name and total salary for those employees whose total salary is more than 10,000. Total Salary = BASIC + HRA. At the end, the program should also print the total number of employees whose total salary is more than 10,000.

1 Answers  


What is the meaning of int *x[]();?

1 Answers  


What is the use of bitwise operator?

0 Answers  


write a program that will print %d in the output screen??

9 Answers   Infosys,


Write a program in c to print * * * * * *******

1 Answers  


Categories