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, ...

Get Advanced Topics in Java: Core Concepts in Data Structures now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.