Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a function of input size defined recursively into a direct function of problem input size?

Say I have an algorithm which operates on an input of size n and I know that the time it takes for n is twice the time it takes for n-1. I can observe in this simple case (assuming it takes, say, 1 second for n = 0) that the algorithm takes 2n seconds.

Is there a general method for converting between recursively-defined definitions to the more familiar direct type of expression?

like image 321
NellerLess Avatar asked Jan 31 '26 00:01

NellerLess


1 Answers

Master Theorem

In particular:

With T(n) = aT(n/b) + nc

If logba < c, then T(n) = O(nc)

If logba = c, then T(n) = O(nclog[n])

If logba > c, then T(n) = O(nlogba)

That's one useful theorem to know, but doesn't fully answer your question.

What you are looking for is the generator function of a recurrence relation. In general, these are only solvable for very simple cases, i.e. when f(n) = Af(n-1) + Bf(n-1) and f(0) = f(1) = 1 (or f(1) = A). Other recurrence relations are very difficult to solve.

See linear recurrence relation for more info.

like image 155
Peter Alexander Avatar answered Feb 03 '26 08:02

Peter Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!