2017-10-13 127 views

回答

0

爲什麼你必須在這裏使用主定理?它可以直接解決這樣的:

T(n) = T(n-1) + n^3 
T(n-1) = T(n-2) + (n-1)^3 
T(n-2) = T(n-3) + (n-2)^3 
.   .  . 
.   .  . 
.   .  . 
T(1) = T(0) + 1^3 
----------------------- (Add them all and cancel) 

T(n) = T(0) + (n(n-1)/2)^2 (Sum of the cubes of the first n numbers) 

因此,這是O(n^4)

+0

聰明的想法。 – flower

+0

好吧,我明白了,但這樣計算太複雜,謝謝你的回答。我提出了你的答案,但由於我的名聲不到15,它還沒有顯示出來。 – flower

+0

但就是這樣。看看這個(https://brilliant.org/wiki/sum-of-n-n2-or-n3/)。解決「嘗試自己」的挑戰,那麼你將獲得更多關於如何解決序列的知識。 – Miraj50

0
T(n) = T(n-1) + n^3 
    = T(n-2) + n^3 + (n-1)^3 
    = T(n-i+1) + (n-i)^3 + ... + (n-1)^3 + n^3 
    = 1^3 + 2^3 + ... + (n/2)^3 + (n/2+1)^3 + ... + (n-1)^3 
    Throw bottom half and decrease the half top to n/2 
    > ((n/2)^3)*(n/2) 
    Ω(n^4) 

    Increase all to (n-1) 
    = 1^3 + 2^3 + ... + (n/2)^3 + (n/2+1)^3 + ... + (n-1)^3 < (n-1)^3*n = O(n^4) 


    T(n) = θ(n^4) 
+0

好的解決方法謝謝,有沒有辦法直接計算1^3 + 3^3 + ... +(n + 2)^ 3? – flower