reversearray( , , - in generalif one has difficulty finding the repetitive structure needed to design recursive algorithmit is sometimes useful to work out the problem on few concrete examples to see how the subproblems should be defined tail recursion using recursion can often be useful tool for designing algorithms that have elegantshort definitions but this usefulness does come at modest cost when we use recursive algorithm to solve problemwe have to use some of the memory locations in our computer to keep track of the state of each active recursive call when computer memory is at premiumthenit is useful in some cases to be able to derive nonrecursive algorithms from recursive ones we can use the stack data structurediscussed in section to convert recursive algorithm into nonrecursive algorithmbut there are some instances when we can do this conversion more easily and efficiently specificallywe can easily convert algorithms that use tail recursion an algorithm uses tail recursion if it uses linear recursion and the algorithm makes recursive call as its very last operation for examplethe algorithm of code fragment uses tail recursion to reverse the elements of an array it is not enough that the last statement in the method definition include recursive callhowever in order for method to use tail recursionthe recursive call must be absolutely the last thing the method does (unless we are in base caseof coursefor examplethe algorithm of code fragment does not use tail recursioneven though its last statement includes recursive call this recursive call is not actually the last thing the method does after it receives the value returned from the recursive callit adds this value to [ and returns this sum that isthe last thing this algorithm does is an addnot recursive call when an algorithm uses tail recursionwe can convert the recursive algorithm into nonrecursive oneby iterating through the recursive calls rather than calling them explicitly we illustrate this type of conversion by revisiting the problem of reversing the elements of an array in code fragment we give nonrecursive algorithm that performs this task by iterating through the recursive calls of the algorithm of code fragment we initially call this algorithm as iterativereversearray ( , code fragment reversing the elements of an array using iteration