Book contents
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
8 - Recursion
from PART ONE - FOUNDATIONS
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
Summary
An essential and important part of computer problem solving is the development of algorithms – the detailed logic and steps required to solve a problem. All programmers are introduced very early to a number of useful programming constructs for building algorithms. These include assignment, branching, and iteration. Branching provides a means for conditional or alternative execution of steps in an algorithm. Iteration provides a convenient way to perform repetitive steps. Without branching and iteration the algorithms for even simple problem solutions would be either impossible or verbose and cumbersome. Another useful concept for construction of algorithms is recursion. Recursion is a construct that provides an alternative to iteration for repetitive steps. In many problems requiring repetitive steps we may find equivalent iterative and recursive algorithms as solutions.
What is recursion? A recursion may be described as the process of executing the steps in a recursive algorithm. So what is recursive? We sometimes tell our students, “If you look up ‘recursive’ in the dictionary, its definition is ‘see recursive.’” We deduce from this anecdotal definition that a recursive algorithm is defined in terms of itself. The actual definition found in one dictionary, “pertaining to or using a rule or procedure that can be applied repeatedly,” is not very helpful.
In developing an understanding for recursion we rely on its use in mathematics, algorithms, and computer programming. From mathematics we find recursive functions defined in terms of themselves.
- Type
- Chapter
- Information
- Fundamentals of OOP and Data Structures in Java , pp. 135 - 154Publisher: Cambridge University PressPrint publication year: 2000