I ran out of memory trying to solve a problem with only 4 disks. With 6 disks, that's a total of 1.14*10^30 moves to keep track of. Just as an example for any number of disks. It's a ridiculous number of nodes at the 63rd level and if you want to be able to follow the path, you have to keep track of everything. Each node contains a value and the next node. Each peg is is a an object that implements a stack data structure. That means that with a BFS search, there would be 63 different levels.not including the root. The Tower of Hanoi puzzle uses three pegs. For example, if there are 6 disks on the tree, the solution takes (2^6)-1 moves to solve or 63 moves to solve. Just to add to this, a Breadth-First Search is crazy memory intensive if you are trying to re-create the path. $60 per hour of my time sounds reasonable. That's why it's called an uninformed search. You don't build the whole tree and then search through it. The BFS doesn't know anything about the tree until it builds the children. So, implement this algorithm to solve the problem. Wikipedia has a good animation to show the steps to take ( Animated_BFS.gif) If none of the children solve it, look at the first child and add in it's children. Does that solve it? If not, look at the next child. Proficient in Pascal, C, C++, IDL and MATLAB Author has 1.2K answers and. So, to start, you have two moves that you can make.move the top disc to the middle, or to the opposite end. Heres how you can solve Tower of Hanoi without using recursion using the. Then, you build the child nodes of that root node and link them as neighbors. So, how would you do that? The question is trying to get you to implement each algorithm to find the solution.įor BFS, how does the algorithm work? Well, you start with the root node. Tower of hanoi - File Exchange - MATLAB Central File Exchange File Exchange My File Exchange Publish About Trial software Tower of hanoi Version 1.0.0.0 (1.1 KB) by Tamir Completes towers of hanoi problem 0. Now, implement the Breadth-First Search algorithm to find the solution. You only know that you have 3 pegs, you can only move one disc at a time, and you cannot move a larger disc onto a smaller disc. You apparently took that to mean, implement the recursive solution as shown on wikipedia's entry for Tower of Hanoi and then you're somehow trying to figure out how to include the different algorithms into it.Īs far as I can tell, here is what you're supposed to do.Īssume you have no knowledge of the way to solve the problem. By your first sentence, you're supposed to find a solution the Tower of Hanoi problem using BFS, DFS, and IDS algorithms. You're not understanding the problem as it was given to you. You're going to have some serious trouble in school my friend.
0 Comments
Leave a Reply. |