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)...

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


Please Help Members By Posting Answers For Below Questions

Do you have any idea how to compare array with pointer in c?

986


Explain can static variables be declared in a header file?

1103


writ a program to compare using strcmp VIVA and viva with its output.

1974


Write a program to reverse a string.

1018


What is difference between class and structure?

1062


What is c language & why it is used?

1027


Explain what is the concatenation operator?

1104


Explain the difference between malloc() and calloc() function?

985


How can a program be made to print the line number where an error occurs?

1035


What is wrong with this initialization?

953


What is the difference between c &c++?

1079


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

1010


count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array

1037


Can you write the function prototype, definition and mention the other requirements.

1082


Is array name a pointer?

993