CHAPTER 5

Recursion

In this chapter, we will explain the following:

- What a recursive definition is
- How to write recursive functions in Java
- How to convert from decimal to binary
- How to print a linked list in reverse order
- How to solve Towers of Hanoi
- How to write an efficient power function
- How to sort using merge sort
- How to use recursion to keep track of pending subproblems
- How to implement backtracking using recursion by finding a path through a maze

5.1 Recursive Definition

A *recursive definition* is one that is defined in terms of itself. Perhaps the most common example is the *factorial* function. The factorial of a non-negative integer, ...

Start Free Trial

No credit card required