Gregory M. Kapfhammer
Details in the Textbook
Method makes one or more calls to itself
Process stops when a base case is reached
Visualized with a call tree or a program stack
Data structure relies on smaller instances of itself
Any questions about the definitions?
Recursive factorial and recursive GCD
Can you find the recursive call?
Can you find the base case?
How do these programs work?
Work with a partner to implement Code Fragment 5.5
Save the method in a file called
Make sure to implement a
Try this method out on a small directory structure
How long did it take to traverse the directories?
Incorrect recursion leads to inefficient algorithms
Be careful about how many recursive calls you create!
Details vary depending on JVM implementation
Possible to store about 1000 simultaneous calls
What happens when you exceed the limit?
Be careful to avoid StackOverflow exceptions!