Solving a recurrence relation using iteration method

扶醉桌前 提交于 2019-12-07 09:08:37

问题


Consider this example :

T(n) = T(7n/8) + 2n 

I assumed T(1) = 0

and tried to solve it in the following way

T(n) = T(7n/8) + 2n
     = T(49n/64) + 2.(7n/8) + 2n
     = T(343n/512) + 2.(7n/8).(7n/8)+ 2.(7n/8) + 2n 
     = T(1) + 2n ( (7n/8)^i + ..... + 1)               

but I could not come to any conclusion about this. I am confused about what should I do in the next step.


回答1:


Your approach is sound, but you'll see what to do if you rewrite it slightly differently:

T(n) = T((7/8)^1 * n) + 2 * (7/8)^0 * n
     = T((7/8)^2 * n) + 2 * (7/8)^1 * n + 2 * (7/8)^0 * n
     = T((7/8)^3 * n) + 2 * (7/8)^2 * n + 2 * (7/8)^1 * n + 2 * (7/8)^0 * n
     .
     .
     .
     = T((7/8)^k * n) + 2 * n * sum j = 0 to k-1 (7/8)^j

Now, let k tend to infinity and see what happens. It would help if you're familiar with geometric series.




回答2:


T(n) = T(7n/8) + 2n = 2n * (1 + 7/8 + (7/8)^2 + ... (7/8)^Z) + T(1) where Z = ?

The only trick is finding Z. I bet a log will help. Sorry it is late, and I am not thinking straight, but ... you should not need to add multiple 2n.

Edit: Z is how many time you need to multiply n by 7/8 until you get 1.

So, n * 7^Z / 8^Z = 1

(7/8)^Z = 1/n

(8/7)^Z = n

You want to solve for Z.




回答3:


What you got there in the last line is a geometric series and there is a formula to simplify such a sum.



来源:https://stackoverflow.com/questions/2053459/solving-a-recurrence-relation-using-iteration-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!