Which search algorithm is most appropriate for solving the Towers of Hanoi? More specifically, of the uninformed search algorithms breadth-first search, depth-first search, and iterative deepening, which would be best?
1 Answers
I'd argue that none of these algorithms would be the best way to solve Towers of Hanoi. The Towers of Hanoi puzzle is well-studied and we have some great solutions to it, some that work recursively and others that work by looking at patterns in the bits of numbers.
Any of the uninformed search strategies given above will run into trouble fairly quickly solving Towers of Hanoi because the search space is so big. With n disks, there are 3n possible states to the puzzle (each disk can be in one of three spots) and the shortest possible solution to the puzzle has length 2n - 1. You're likely to end up exploring the full search space if you used any of the uninformed strategies, and for any reasonable value of n the cost of holding 3n states in memory (which you'd need for BFS) or a sequence of at 2n - 1 states in memory (for DFS or IDDFS) would be prohibitive. Contrast this with the binary counting solution to Towers of Hanoi or the standard recursive algorithm for Towers of Hanoi, each of which uses only O(n) total memory.

- 362,284
- 104
- 897
- 1,065