Help with question [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_开发知识库 Improve this questionTwo algorithms A and B solve the same algorithmic problem, A taking n^3 seconds and B taking n days.
(i) Which algorithm is asymptotically preferable?
(ii) How large does n need to be before B takes one-quarter of the time taken by A?
How do I go about solving these?
My answer for (i) is that B is preferable as n grows at a faster rate asymptotically. Days and seconds here count as a constant and therefore do not matter as n approaches infinity.
for ii) my guess is 2 days. But wondered if others got the same
I could be completely wrong here, but I think you want this
24*60*60*n = n^3 * 1/4
which when plugged into wolphram alpha gives
587.87....
or
-587.87 in some alternate universe ;)
This looks like a brute force type of algorithm would work to give you a better feal for the problem. I would take a look at the total time it takes for the two functions to be equal and what happens above and below that threshold. Also, for good practice it may be good to look for multiple solutions.
y=n^3 seconds
y=n * (60 seconds * 60 minutes * 24 hours) seconds = n seconds per day
Then look through incrementing values of n for points where the value of y is equal between the two functions.
精彩评论