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
what is the structure pointer?
Can we declare variable anywhere in c?
What is calloc in c?
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
how many key words availabel in c a) 28 b) 31 c) 32
Why c is called top down?
What is I ++ in c programming?
Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
How can I write a function that takes a format string and a variable number of arguments?
What are bitwise shift operators in c programming?
How can I write functions that take a variable number of arguments?
How can I read in an object file and jump to locations in it?
What does *p++ do? What does it point to?
What is c language used for?