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 |
write a c program to print a given number as odd or even without using loop statements,(no if ,while etc)
Describe the order of precedence with regards to operators in C.
What is #include stdlib h?
Explain null pointer.
pgm to find middle element of linklist(in efficent manner)
How many data structures are there in c?
O,T,T,F,F,S,S,E,N,?,?,?,T,F,F,S,S,E,N
5. distance conversion: Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer
what is mean by Garbage collection ? Please answer me. Advance thanks.
How can you avoid including a header more than once?
What is the difference between ++a and a++?
main() { int i,j,A; for(A=-1;A<=1;A++) prinf("%d\t",!!A); }