问题
I'm trying to figure out the runtime of an algorithm. It is a sort which works by dividing the problem up into sets of 2/3's (it's the CLR sort). I'm having some trouble coming up with it, this is what I have:
T(n)=3T([2n]/3)+1 (the 1 is because aside from the recursive calls, there is one exchange which may or may not be made. Assuming it is done, it is still only a constant cost.)
T(n)=3T([2([2n]/3+1)]/3+1)+1
T(n)=3T([2([2([2n]/3+1)]/3+1)]/3+1)+1
T(n)=3T([2([2([2([2n]/3+1)]/3+1)]/3+1)]/3+1)+1
etc......until we can assume that at some point we finally hit the base case for T(n) and get a constant value of 1 for that runtime. This gives us:
3([2([2([2([2(...........)]/3+1)]/3+1)]/3+1)]/3+1)+1 with logn terms (that's the "......." in the middle). This gives:
3*(2n/3+1)^(logn)+1*logn
3*(2n/3+1)^(logn)+logn
Then I think that since, if the base of the log were 2n/3+1, we could simplify it to simply be 3*logn+logn, we can do so. (I keep hearing that when doing asymptotic notation, the bases of the logs which we chose don't matter....)
This becomes 4logn. The coefficient drops away to become simply logn.
Is this correct? I'm not sure if I expanded this properly, or if my log manipulations were legal...Also, what is this final result--big-O, theta, etc. I'm not sure what I'm looking at...
Thanks.
回答1:
You can look at this page to get you a general recurrence relation solution for divide and conquer algorithms.
In this case, b = 3/2, a = 3, and f(n) = O(1). log base 3/2 of 3 is about about 2.709, so we use case 1, which means the run time is O(n^2.709).
Hope that helps!
来源:https://stackoverflow.com/questions/14888827/trouble-trying-to-find-the-asymptotic-runtime-of-a-recurrence