Abstract
In this chapter, we learn the technique called backtracking . Backtracking is a systematic method of trial and error. In short, it is an approach that tests all possible choices, looking for the desired solution. Up to this point, it is similar to the DFS and BFS algorithms discussed in Chap. 4 and, like these algorithms, checks in the search tree systematically in order. The main feature of backtracking is that, if it finds at some point that there is no possibility of finding a solution, it halts the search, returns to the last branch, and turns to the next choice that has not yet been tested. This trick—return and turn to the next choice—is the reason why this method is called “backtracking.” If we can halt the redundant searching, even if the search tree is huge, we may find a solution efficiently.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Application of sentinel: We can omit this check of “outside the board” using the technique called sentinel. If you have enough energy, consider how you can realize this.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2019 Springer Nature Singapore Pte Ltd.
About this chapter
Cite this chapter
Uehara, R. (2019). Backtracking. In: First Course in Algorithms Through Puzzles. Springer, Singapore. https://doi.org/10.1007/978-981-13-3188-6_5
Download citation
DOI: https://doi.org/10.1007/978-981-13-3188-6_5
Published:
Publisher Name: Springer, Singapore
Print ISBN: 978-981-13-3187-9
Online ISBN: 978-981-13-3188-6
eBook Packages: Computer ScienceComputer Science (R0)