帮助解决问题

时间:2011-05-18 16:36:17

标签: algorithm math

Two 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?

我如何解决这些问题?

我对(i)的回答是B是优选的,因为n渐近地以更快的速度增长。这里的天数和秒数都算作常数,因此当n接近无穷大时无关紧要。

对于ii)我的猜测是2天。但是想知道其他人是否也有同样的想法

2 个答案:

答案 0 :(得分:1)

我在这里可能完全错了,但我想你想要这个

24*60*60*n = n^3 * 1/4  

当插入wolphram alpha时会给出

587.87 ...

某些替代宇宙中的

-587.87;)

答案 1 :(得分:0)

这看起来像一种强力类型的算法可以帮助您更好地解决问题。我将看一下两个函数相等所需的总时间以及在该阈值之上和之下发生的事情。此外,对于良好的实践,寻找多种解决方案可能会很好。

y=n^3 seconds
y=n * (60 seconds * 60 minutes * 24 hours) seconds = n seconds per day 

然后通过递增n的值来获得两个函数之间y的值相等的点。