I'm having a problem understanding recursion. I understand that it is like a continous loop that breaks down your big problem into little ones, but implementing it is a prob. I am taking an online C++ course (that probably a problem in itself) that gave a homework assignment that involves recursion.
2.7 Implement maxarray, discussed in the section “Finding the Largest Item in an Array,” as a recursive C++ function. Note the call tree on page 84 uses a helper function named max. What does the name max imply as the purpose of the function? You will write this helper function.
Well the figure on p84 looks pretty much like
MaxArray(<1,6,8,3>)
return max(maxArray(<1,6>) , maxArray(<8,3>)
| |
maxArray(<1,6>) maxArray(<8,3>)
return max(<1>), maxArray(<6>) return(maxArray<8>),maxArray(<3>)
| | | |
maxArray(<1>) maxArray(<6>) maxArray(<8>), maxArray(<3>)
return 1 return 6 return 8 return 3
Any ideas ?Any help is appreciated