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 Posted / 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 View All Answers
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
What are the types of data types and explain?
What is chain pointer in c?
a value that does not change during program execution a) variabe b) argument c) parameter d) none
What is the purpose of ftell?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
Who invented bcpl language?
What is string concatenation in c?
define string ?
Why is it usually a bad idea to use gets()? Suggest a workaround.
Explain how does flowchart help in writing a program?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
What is #include called?
What is difference between %d and %i in c?
Write a program to show the change in position of a cursor using c