Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top