I have an algorithm that does O(n) work, gets rid of a constant fraction 1/k of the input (k > 2), and calls itself recursively on what remains. The algorithm can be described by T(n) = T( ( (k-1)/k)*n)+O(n). How do I calculate the closed form for T(n).
2 Answers
You can expand it directly: T(n) = T(((k - 1)/k)^2 * n) + O(((k - 1)/k) * n) + O(n) and so on
Note that n * ((k-1)/k) is n / (k / (k - 1)) which implies a denominator > 1.
Hence it is a geometric series that converges to a sum n / ( 1 - (k - 1)/k) = n * k.
Hence T(n) = O(n*k) which is O(n) if k is constant.
6 Comments
You might want to read about the Master Theorem, which is a convenient way to analyze this kind of problems: http://en.wikipedia.org/wiki/Master_theorem
Your algorithm would fall into case 3, where the recursive work is negligible compared to the work outside.