This chapter covers
- Recursion for designing solutions to programming problems
- Dynamic backtracking to try different solution paths during run time
Recursion is a software design technique used to create solutions to certain programming problems. It involves a function that calls itself, and nearly all modern programming languages support this important technique. If we use recursion properly with certain classes of programming problems, we can design solutions that are simple, elegant, and as some might claim, magical. With recursion, we can design solutions that may be difficult to solve otherwise.
Recursion requires a different way of thinking about how to design a programming solution to a problem. Unfortunately, for some programmers, it is too mysterious and forbidding to use. This chapter clears away the mystery and demonstrates how combining recursion with dynamic backtracking gives us even more powerful design tools. However, we’ll also see how misusing recursion can lead to surprising performance disasters. With experience, we can learn when it is appropriate to design with recursion.