Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 you increase the size of a statically allocated array?

0 Answers   TISL,


how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk.

3 Answers   Google,


What is the difference between NULL and NUL?

0 Answers   Aspire, Infogain,


What are directives in c?

0 Answers  


how to write palindrome program?

3 Answers  


how can i print "hello".please consider inverted commas as well.i want to print on console: "hello"

4 Answers   Wipro,


cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

0 Answers  


How to declare pointer variables?

0 Answers  


differnce between do and do while

3 Answers   DOEACC,


Write code for initializing one dimentional and two dimentional array in a C Program?

5 Answers   Deshaw, Edutech, GMD,


Write a c program to sort six numbers and find the largest one by using the ladder of if-else? plz do help me

2 Answers  


wat is the difference between a definition and declaration? float y;---it looks like a declaration..but it s a definition.how?someone explain

3 Answers   TCS,


Categories