Edit: I am not looking for an algorithm, but actually a math equation similar to f(i) = sum i=0 to n-1 (C * A[i]), but with respect to n (length of the array) rather than i (iteration #).
I have an algorithm that loops through an array A of size n (with elements A[0] to A[n-1]) and does some computation with the elements of the array. I managed to extract the following recursive function f(i) for the output value of the algorithm, where i is the iteration of the loop:
- f(0) = A[n-1]
- f(i) = C * f(i-1) + A[n-1-i]
...where C is an integer constant.
Knowing that we loop through the whole array, we do n-1 iterations (we handle f(0) before the loop). I would like to express this recursive function as a direct iterative function, e.g. f(i) = sum i=0 to n-1 (C * A[i]), but I can't figure out how (it definitely isn't as simple as my example, if doable). I don't really know a formal method for doing this kind of thing, I usually figure it out by intuition for simpler problems.
Is it doable? If so, how? Hopefully I was clear enough, thanks.