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)...
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 |
What are the primitive data types in c?
what is the difference between embedded c and turbo c ?
What is a pointer in c?
What is c mainly used for?
What is the advantage of using #define to declare a constant?
0 Answers Agilent, ZS Associates,
write an algorithm and a program to count the number of elements in a circularly singly linked list
Explain threaded binary trees?
What is time complexity c?
why TCS selected more student in the software field from all institution.
why integer range between -327680to+32767
Write a program in c to input a 5 digit number and print it in words.
Is it possible to create recycle bin in mobiles?