Solved

tower of hanoi

Posted on 2000-03-10
9
714 Views
Last Modified: 2008-03-06
What is the algorithm for depth-first search for tower of hanoi!
0
Comment
Question by:fifi129
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

710 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