簡體   English   中英

如何使用主定理計算遞歸,除法和征服

[英]How to use master theorem to calculate recursion, divide and conquer

我想計算Θ()

Given T (n) = T (n − 1) + n^3

我無法直接應用主定理規則,因為我不知道b是什么,那么如何得出Θ()呢?

為什么在這里必須使用Master定理? 可以這樣直接解決:

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)

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM