Java Reference
In-Depth Information
18.1 Introduction
18.2 Recursion Concepts
18.3 Example Using Recursion: Factorials
18.4 Reimplementing Class
FactorialCalculator Using
Class BigInteger
18.5 Example Using Recursion: Fibonacci
Series
18.6 Recursion and the Method-Call Stack
18.7 Recursion vs. Iteration
18.8 Towers of Hanoi
18.9 Fractals
18.9.1 Koch Curve Fractal
18.9.2 (Optional) Case Study: Lo Feather
Fractal
18.10 Recursive Backtracking
18.11 Wrap-Up
Summary | Self-Review Exercises | Answers to Self-Review Exercises | Exercises
18.1 Introduction
The programs we've discussed so far are generally structured as methods that call one an-
other in a hierarchical manner. For some problems, it's useful to have a method call itself .
A method that does so is known as a recursive method . A recursive method can call itself
either directly or indirectly through another method . Recursion is an important topic dis-
cussed at length in upper-level computer science courses. In this chapter, we consider re-
cursion conceptually, then present several programs containing recursive methods.
Figure 18.1 summarizes the recursion examples and exercises in this topic.
Chapter
Recursion examples and exercises in this topic
18
Factorial Method (Figs. 18.3 and 18.4)
Fibonacci Method (Fig. 18.5)
Towers of Hanoi (Fig. 18.11)
Fractals (Figs. 18.18 and 18.19)
What Does This Code Do? (Exercise 18.7, Exercise 18.12 and Exercise 18.13)
Find the Error in the Following Code (Exercise 18.8)
Raising an Integer to an Integer Power (Exercise 18.9)
Visualizing Recursion (Exercise 18.10)
Greatest Common Divisor (Exercise 18.11)
Determine Whether a String Is a Palindrome (Exercise 18.14)
Eight Queens (Exercise 18.15)
Print an Array (Exercise 18.16)
Print an Array Backward (Exercise 18.17)
Minimum Value in an Array (Exercise 18.18)
Star Fractal (Exercise 18.19)
Maze Traversal Using Recursive Backtracking (Exercise 18.20)
Generating Mazes Randomly (Exercise 18.21)
Mazes of Any Size (Exercise 18.22)
Time to Calculate a Fibonacci Number (Exercise 18.23)
Fig. 18.1 | Summary of the recursion examples and exercises in this text. (Part 1 of 2.)
 
 
Search WWH ::




Custom Search