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.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With