2011-05-18 46 views
0
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)的回答是,隨着n以漸近的速度增長,B更可取。這裏的天和秒數是一個常數,因此當n接近無窮大時無關緊要。對於ii)我的猜測是2天。但是,不知道是否其他人得到了相同的

+1

我想回答,但這真的屬於http://math.stackexchange.com – 2011-05-18 16:39:22

+0

嘗試和寫在(ii)中的信息在一個等式中。認爲簡單。同樣,如果我說兩個蘋果花費10美元,你會說'2x = 10'並解決x,在這裏做n。 – davin 2011-05-18 16:40:21

+1

但實際上你只需要爲方程(1/4)(n^3)= 24 * 60 * 60 * n'求解n。這很容易解決。 – 2011-05-18 16:41:03

回答

1

我可能是完全錯誤的在這裏,但我想你想這

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

,當插入wolphram alpha

587.87 ....

-587.87在一些替代宇宙;)

0

這看起來像一個蠻力類型的算法會工作給你一個更好的問題。我會看看這兩個函數相等所需的總時間以及高於和低於該閾值的情況。另外,對於良好的做法,尋找多種解決方案可能會很好。

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

然後查看n的遞增值,其中y的值在兩個函數之間相等。