從新粗推了一下Master Theorem

主定理通常形式是T(n) = a T(n / b) + f(n), a >= 1, b > 1。遞歸項能夠理解爲一個高度爲 logbn 的 a 叉樹, 這樣 total operation就是  (a ^ logbn) - 1,  右邊的f(n)假設爲 nc 那麼咱們對比一下這兩項就會發現 T(n)的複雜度主要取決於 logba 與 c 的大小。因此咱們纔會有接下來的三種case。也須要注意何時不可使用主定理。遞歸

Case 1:  c < logba ,   O(n) = n ^ logba  , 意味着咱們能夠忽略 f(n)ip

Case 2:  c = logba,    O(n) = nlogk + 1n   ,  k >= 0rem

Case 3:  c > logba,    O(n) = ncio

 

Reference:ast

https://en.wikipedia.org/wiki/Master_theoremdi

相關文章
相關標籤/搜索