Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- Part Two Recursion
- Part Three Optimization Problems
- 13 Definition of Optimization Problems
- 14 Graph Search Algorithms
- 15 Network Flows and Linear Programming
- 16 Greedy Algorithms
- 17 Recursive Backtracking
- 18 Dynamic Programming Algorithms
- 19 Examples of Dynamic Programs
- 20 Reductions and NP-Completeness
- 21 Randomized Algorithms
- Part Four Appendix
- Part five Exercise Solutions
- Index
17 - Recursive Backtracking
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- Part One Iterative Algorithms and Loop Invariants
- Part Two Recursion
- Part Three Optimization Problems
- 13 Definition of Optimization Problems
- 14 Graph Search Algorithms
- 15 Network Flows and Linear Programming
- 16 Greedy Algorithms
- 17 Recursive Backtracking
- 18 Dynamic Programming Algorithms
- 19 Examples of Dynamic Programs
- 20 Reductions and NP-Completeness
- 21 Randomized Algorithms
- Part Four Appendix
- Part five Exercise Solutions
- Index
Summary
The brute force algorithm for an optimization problem is to simply compute the cost or value of each of the exponential number of possible solutions and return the best. A key problem with this algorithm is that it takes exponential time. Another (not obviously trivial) problem is how to write code that enumerates over all possible solutions. Often the easiest way to do this is recursive backtracking. The idea is to design a recurrence relation that says how to find an optimal solution for one instance of the problem from optimal solutions for some number of smaller instances of the same problem. The optimal solutions for these smaller instances are found by recursing. After unwinding the recursion tree, one sees that recursive backtracking effectively enumerates all options. Though the technique may seem confusing at first, once you get the hang of recursion, it really is the simplest way of writing code to accomplish this task. Moreover, with a little insight one can significantly improve the running time by pruning off entire branches of the recursion tree. In practice, if the instance that one needs to solve is sufficiently small and has enough structure that a lot of pruning is possible, then an optimal solution can be found for the instance reasonably quickly. For some problems, the set of subinstances that get solved in the recursion tree is sufficiently small and predictable that the recursive backtracking algorithm can be mechanically converted into a quick dynamic programming algorithm. See Chapter 18. In general, however, for most optimization problems, for large worst case instances, the running time is still exponential.
- Type
- Chapter
- Information
- How to Think About Algorithms , pp. 251 - 266Publisher: Cambridge University PressPrint publication year: 2008
- 1
- Cited by