Solved

tower of hanoi

Posted on 2000-03-10
9
713 Views
Last Modified: 2008-03-06
What is the algorithm for depth-first search for tower of hanoi!
0
Comment
Question by:fifi129
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2605145
Is this a school assignment>
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2605164
..
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2605188
Looks like it doesn't it.
Can you be a bit more precise? We don't want to make your homework, but we can help with problems you encounter while making the assignment.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Expert Comment

by:sunsetyang
ID: 2607652
the graph describe the search:
              (n,0,0)
               |     \
          (n-1,1,0)  (n-1,0,1)
          |    \         |      \
  (n-2,1,1) (n-1,0,1)(n-1,1,0) (n-2,1,1)
  ....................
the algorithm will look like:
 move_tower(a,b,c)
{  
 //source a,target c,b is additional:
 check feasible placement,then choose one;
 move_piece(1,a,b or c);//move one piece from a to b or c;
 if(succeed()) return;
  move_tower(a b c);
}
You need to add depth limit to the recursive calls,and to record its status so not to do the non-stop calling.Then the second level's second status,won't appear ,for it is the same as the third level's second status.
Perhaps it's wrong.
0
 

Author Comment

by:fifi129
ID: 2607868
Thanks a lot
But how can i perform the backtrack
(check the moved pattern existed in its ancester or not)
(All node in the path of the tree should be unique)

Thank you

Fannie
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2608171
See
http://www.pangea.ca/kolar/javascript/Hanoi/HTonWebE.html
for links to web resources and(for example)
http://www.pangea.ca/kolar/javascript/Hanoi/algo.html
for fast non recursive algorithm(+source
text)
Alex
0
 

Author Comment

by:fifi129
ID: 2609691
I've already visit the sites.

Anyway, thanks to all of you
0
 

Accepted Solution

by:
slavik022300 earned 75 total points
ID: 2616283
I'll send you the algorithm by e-mail today.
My e-mail is slv@writeme.com
0
 
LVL 22

Expert Comment

by:nietod
ID: 2616326
Is there are reason why you can't post the solution here?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question