1 / 1

Ch 17 Recursion Lab – Tower’s of Hanoi

Ch 17 Recursion Lab – Tower’s of Hanoi.

sally
Download Presentation

Ch 17 Recursion Lab – Tower’s 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. Ch 17 Recursion Lab – Tower’s of Hanoi • Every budding computer scientist must grapple with certain classic problems, and the Tower’s of Hanoi is one of the most famous. Legend has it that in a temple in the Far East, priests are attempting to move a stack of disks from one peg to another peg. The initial stack has 64 disks threaded onto one peg and arranged from bottom to top by decreasing size. The priests are attempting to move the stack from one peg to another peg – subject to two constraints : • Only one disk is moved at a time. • At no time may a larger disk be placed above a smaller disk. A third peg is available for temporary storage of disks. • The monks believed the world would end and humankind would be freed from suffering when the task was finally completed. • Mathematically speaking for n rings, 2n – 1 separate moves are required to complete the task. At the rate of one move per second, 264-1 moves take about 600 billion years! • Recursively, moving n disks can be viewed in terms of moving only n-1 disks as follows: • Move n – 1 disks from peg 1 to peg 2, using peg 3 temporarily. • Move the last disk ( largest ) from peg 1 to peg 3. • Move the n – 1 disks from peg 2 to peg 3, using peg 1 as storage. • The process ends when the last task involves moving n = 1 disk (base case). This task is accomplished by simply moving the disk, without the need for a temporary holding area.

More Related