# Derivation of the formula of Hanoi pass term

Source: Internet
Author: User

Hanoi pass Formula Proof:

Set three towers for a, B, C, respectively. When a tower has n plates initially, it needs T (n) steps to transfer to Tower C.

First, there are the following rules:

T (0) = 0 (of course 0 when there is no plate)

T (1) = 1

T (2) = 3

T (3) = 7

... /p>

T (n) = t (n-1) + 1 + t (n-1) = (n-1) + 1

Why t (n) = 2 * t (n-1) + 1?

It is easy to think that when n = n-1,

(1) The number of steps required to move all plates from tower A to Tower C is T (n-1).

(2) If the number of steps moved from a to C is T (n-1), then moving from A to B also requires T (n-1)

So when n = N:

(1) First move all trays of a tower to Tower B, need t (n  -1 Step

(2) moves the last plate of tower A to tower C, which requires 1 steps

(3) to move all trays of Tower B to tower C, requiring t (n  -1) steps. The

Final result requires a T (n  -1) + 1 step.

So T (n) = 2 * t (n  -1) + 1

What is the general formula? How do you prove it?

is simple ~

To add 1 to both ends of the equation:

T (n) + 1 = 2 * (t (n-1) + 1)

Set T (n) + 1 = S (n)

Then: s (n) = 2 *s (n-1)

And when n = 1, S (1) = 1;

Then s (n) = 2 ^ n

So: T (n) + 1 = S (n) = 2 ^ n

That is   T (n) = 2 ^ n-1

The

is completed.

Hanoi formula derivation

Related Keywords:

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.