1 / 3

The Towers of Hanoi

The Towers of Hanoi. The Tower of Hanoi puzzle was invented in the 1880s by Edouard Lucas, a French mathematician. It has become a favorite among computer scientists because of its solution is an excellent demonstration of recursive elegance. The Towers of Hanoi.

Download Presentation

The Towers of Hanoi

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Towers of Hanoi • The Tower of Hanoi puzzle was invented in the 1880s by Edouard Lucas, a French mathematician. • It has become a favorite among computer scientists because of its solution is an excellent demonstration of recursive elegance.

  2. The Towers of Hanoi • The puzzle consists of three upright pegs and a set of disks with holes in the middle so that they slide onto the pegs. • Each disk has a different diameter. • Initially, all of the disks are stacked on one peg in order of size such that the largest disk is on the bottom. • The goal of the puzzle is to move all of the disks from their original peg to the destination peg. • We can use the extra peg as a temporary place to put disks. But we must obey the following rules: • We can move only one disk at a time • We can not place a larger disk on top of a smaller disk • All disks must be on some peg except for the disk in transit between pegs.

  3. Recursion public void moveTower(int num, int start, int end, int temp) { if (num == 1) moveOneDisk(start,end); else { moveTower(num-1, start, temp, end); moveOneDisk(start,end); moveTower(num-1, temp, end, start); } }//end method

More Related