Using VB to write dynamic demonstration program of Hanoi Tower problem

Source: Internet
Author: User
Tags data structures

1 Introduction

In the design of computer algorithms, recursive technique is often used to make the definition of function and the description of the algorithm simple and easy to understand. Some data structures, such as binary trees, are especially suitable to be described in recursive form because of their inherent recursive characteristics. There are some problems, although they do not have a significant recursive structure, but the recursive technology to solve the design of the algorithm is simple and easy to understand. Therefore, it is possible to design a more effective algorithm in the process of the design of the recursive technique [1].

To put it simply, recursion is about defining yourself by yourself. The basic idea of constructing algorithm using recursive method is: When solving the problem of scale N, we first decompose it into several smaller ones with the same characteristics as the original one, find the combinatorial relationship between the sub problem and the original problem, and finally construct the recursive algorithm according to the specific problems.

The execution process of recursive algorithm is divided into two stages, "recursion" and "regression". In the recursive phase, the more complex issues such as: the solution of the scale N) is deduced to the problem that is simpler than the original problem (for example, the scale is n-1), in the regression stage, the solution of the recursive end is regressed, then the solution of the slightly complex problem is obtained, and finally the solution of the original problem is obtained [2].

The Hanoi tower problem is a typical example of a simple algorithm that is suitable for using recursive techniques. The Hanoi tower problem comes from around the end of the 19 century in Europe, a game, the game first in a copper plate placed three pillars, on the first pillar from top to bottom, from small to large sequence string of 64 plates. The goal of the game is to finally move all the plates from the first pillar to the third pillar, where the second pillar can be used to transition. The game stipulates that only one plate can be moved at a time, and the market is not allowed to be placed on the small plate at any time.

Now give a program on the Hanoi Tower problem, and let it demonstrate the implementation of the Hanoi tower problem dynamically to help readers understand recursion technology.

2 algorithm Design

We first use the recursive technique to design the algorithm for this problem. We have three pillars labeled A, B and C respectively, and the goal is to move n plates from column A to pillar C. This problem can be designed with the following recursive algorithm:

The first step is to n-1 a plate on pillar A to move to Pillar B with the help of column C.

The second step moves the remaining nth plate on column A to the C pillar;

The third step is to move the n-1 plate on pillar B to pillar C with the help of a pillar.

For the first and third steps, we can use a similar method to continue to design the solution process to a Hanoi tower recursive algorithm with n-1 scale.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.