Converting Recursion to Iteration

Steven J. Zeil

Old Dominion University, Dept. of Computer Science

Table of Contents

1. A Diversion - Function Calls at the Machine Level
2. Converting Recursive Algorithms to Iteration
2.1. Tail Recursion
2.2. Conversion Using Stacks
2.3. Conversion Example: quickSort
2.4. Last Thoughts
3. Last Thoughts

A common application of stacks is in converting recursive algorithms to iterative forms.

Recursion and iteration (looping) are equally powerful. Any recursive algorithm can be rewritten to use loops instead. The opposite is also true. Any iterative algorithm can be written in terms of recursion only.

Given a choice of which to use, our decision is likey to come down to issues of

In the Forum:

(no threads at this time)