Change a Recursive function that has a for loop in it into an iterative function?
- by Bill
So I have this function that I'm trying to convert from a recursive algorithm to an iterative algorithm. I'm not even sure if I have the right subproblems but this seems to determined what I need in the correct way, but recursion can't be used you need to use dynamic programming so I need to change it to iterative bottom up or top down dynamic programming.
The basic recursive function looks like this:
Recursion(i,j)
{
if(i>j)
return 0;
else
{
//This finds the maximum value for all possible subproblems and returns that for this problem
for(int x = i; x < j; x++)
{
if(some subsection i to x plus recursion(x+1,j) is > current max)
max = some subsection i to x plus recursion(x+1,j)
}
}
}
This is the general idea, but since recursions typically don't have for loops in them I'm not sure exactly how I would convert this to iterative. Does anyone have any ideas?