Towers of Hanoi
Date: 06/21/06
(Algorithms) Keywords: web
I am wondering if anyone on this community knows of a good towers of hanoi tutorial. Here's the problem: I've read several of these tutorials. But to me, they all jump a lot of steps in the explanation. They will say something like: this is a recursive problem. The first thing is to move all of the disks but the first one onto a helper peg. The next step is to move the large peg onto the destination. Then we move the other pages onto the destination peg. It's that easy. And here is the simple algorithm for that: [blah blah blah].
The problem with this type of explanation to me is that it doesn't make it at all clear just how someone devised the algorithm, that is, how they determined the order of the source, destination, and auxiliary arguments for each recursive call. I'm a beginner and I really want someone to break down the problem for me into its smallest possible components, being very explicit about how each line of code is generated. So far, I just haven't seen a site that has done this (which I find really surprising and disappointing, I must say).
Note that I'm not asking for the solution to the problem. That's readily available. What I need to do is understand the process involved in developing the solution, because right now I'm just not getting it. So I would be extremely grateful to anyone who can point me to an exceptionally basic web site on the matter or, if you're extremely kind, try to explain how the solutions knew how to add the extra source, destination, and auxiliarly peg information.
I can show you the part of the problem I understand really well. It's this part, stripped of everything from the disk numbers:
function hanoi(n)
{
if (n == 1)
print(n);
else {
hanoi(n-1);
print(n);
hanoi(n-1);
}
}
But I'm really having trouble understanding how someone gets from the code I just wrote to the full solution...?
Source: http://community.livejournal.com/algorithms/78783.html