Help unrolling a recursive function

1k Views Asked by At

I want to calculate a recursive function $$f : \Bbb{Z} \times \Bbb{Z} \rightarrow \Bbb{Z}$$ $$f(n, m) = f(n,m-1) + f(\lfloor n/m \rfloor,\lfloor n/m \rfloor - 1) + \textrm{other non-recursive stuff}$$ where the areguments are positive integers and we can assume the values for small inputs. (Like $f(1,1)$ or whatever we need). The function I wrote above is a simplified version of what I actually want but it retains the recursive nature. What I want to do now is calculate this from a bottom up direction.

If we just had the first term; that is, say our recursion was $$f(n, m) = f(n,m-1) + \textrm{other non-recursive stuff}$$ then this is easy. You have to calculate $f(n,1)$ and work your way up. I guess what I'd like is some help doing this for my more complicated function above.

Just looking at it ($f$) I have no intuition about how many recursive calls there are, but I seem to break my C code if my inputs are too big. I know that if I 'unroll' the function by computing it from the ground up. I will not break the C code. But I don't want to compute and store $f(n,m)$ for every possible value because THAT would take way too long. (My target $n$ and $m$ are around $10^7$)

This is for a self study class that I am taking. I don't want to post the course or the exact problem for fear of ruining things for others but it seems like others who have done this before me were able to compute this from the bottom-up method without too much trouble.

(not sure on tags)

Thanks in advance.