Book contents
- Frontmatter
- Contents
- Preface
- 1 Introduction to recursion
- 2 Recursion with linked-linear lists
- 3 Recursion with binary trees
- 4 Binary recursion without trees
- 5 Double recursion, mutual recursion, recursive calls
- 6 Recursion with n-ary trees and graphs
- 7 Simulating nested loops
- 8 The elimination of recursion
- Further reading and references
- Index of procedures
8 - The elimination of recursion
Published online by Cambridge University Press: 05 February 2012
- Frontmatter
- Contents
- Preface
- 1 Introduction to recursion
- 2 Recursion with linked-linear lists
- 3 Recursion with binary trees
- 4 Binary recursion without trees
- 5 Double recursion, mutual recursion, recursive calls
- 6 Recursion with n-ary trees and graphs
- 7 Simulating nested loops
- 8 The elimination of recursion
- Further reading and references
- Index of procedures
Summary
We are going to finish our study of recursion in Pascal programming by seeing how to eliminate it. This may seem a curious thing to do given that for seven chapters we have strongly pressed the case for using recursion, but there are a number of reasons for doing so.
Firstly, it may be that the system we are using does not allow recursion. Such a restriction will not arise with Pascal, of course, but sometimes we are obliged to write in Fortran where such a restriction is part of the language definition. If we can translate a recursive procedure into a non-recursive one, then we can still retain the advantages of designing our programs recursively.
Secondly, where there are two or more forms of recursion in a procedure, its readability may be improved by the removal of one of the recursive aspects. We discussed this idea in Chapter 2 and used it in Chapters 5 and 6. For improved readability, the recursion to be eliminated must be of the preorder, linear type.
Thirdly, we may have tight space constraints or very tight time constraints and it may be that the replacement of a recursive procedure by an iterative one allows us to satisfy those constraints.
Finally, and most importantly, we may wish to consider the elimination of recursion purely to increase our understanding of recursive procedures.
- Type
- Chapter
- Information
- Recursion via Pascal , pp. 166 - 189Publisher: Cambridge University PressPrint publication year: 1984