I am refreshing on Master Theorem a bit and I am trying to figure out the running time of an algorithm that solves a problem of size n by recursively solving 2 subproblems of size n-1 and combine solutions in constant time.
So the formula is:
T(N) = 2T(N - 1) + O(1)
But I am not sure how can I formulate the condition of master theorem.
I mean we don’t have T(N/b) so is b of the Master Theorem formula in this case b=N/(N-1)?
If yes since obviously a > b^k since k=0 and is O(N^z) where z=log2 with base of (N/N-1) how can I make sense out of this? Assuming I am right so far?
I am refreshing on Master Theorem a bit and I am trying to figure
Share
ah, enough with the hints. the solution is actually quite simple. z-transform both sides, group the terms, and then inverse z transform to get the solution.
first, look at the problem as
apply z transform to both sides (there are some technicalities with respect to the ROC, but let’s ignore that for now)
solve for X(z) to get
now observe that this formula can be re-written as:
where r = c/(1-a) and s = – a c / (1-a)
Furthermore, observe that
where P(z) = r z / (z-1) = r / (1 – (1/z)), and Q(z) = s z / (z-a) = s / (1 – a (1/z))
apply inverse z-transform to get that:
and
where log denotes the natural log and u[n] is the unit (Heaviside) step function (i.e. u[n]=1 for n>=0 and u[n]=0 for n<0).
Finally, by linearity of z-transform:
where r and s are as defined above.
so relabeling back to your original problem,
then
where exp(x) = e^x, log(x) is the natural log of x, and u[n] is the unit step function.
What does this tell you?
Unless I made a mistake, T grows exponentially with n. This is effectively an exponentially increasing function under the reasonable assumption that a > 1. The exponent is govern by a (more specifically, the natural log of a).
One more simplification, note that exp(log(a) n) = exp(log(a))^n = a^n:
so O(a^n) in big O notation.
And now here is the easy way:
put T(0) = 1
note that this creates a pattern. specifically:
put c = 1 gives
this is geometric series, which evaluates to:
for n>=0.
Note that this formula is the same as given above for c=1 using the z-transform method. Again, O(a^n).