Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve for this recurrence T(n) = T(n − 1) + lg(1 + 1/n), T(1) = 1?

I got stuck in this recurrence:

T(n) = T(n − 1) + lg(1 + 1/n), T(1) = 1?

for a while and it seems the master method cannot be applied on this one.

like image 521
Bee Avatar asked Feb 09 '23 08:02

Bee


1 Answers

We have:

lg(1 + 1/n) = lg((n + 1) / n) = lg(n+1) - lg(n)

Hence:

T(n) - T(n - 1) = lg(n + 1) - lg(n)

T(n-1) - T(n - 2) = lg(n) - lg(n - 1)

...

T(3) - T(2) = lg(3) - lg(2)

T(2) - T(1) = lg(2) - lg(1)

Adding and eliminating, we get:

T(n) - T(1) = lg(n + 1) - lg(1) = lg(n + 1)

or T(n) = 1 + lg(n + 1)

Hence T(n) = O(lg(n))

like image 53
user1952500 Avatar answered Feb 20 '23 14:02

user1952500