Home > IB Computer Science 2016 > Towers of Hanoi

Towers of Hanoi

November 10, 2014 Leave a comment Go to comments

Hanoi

If you have to move n disks from the source peg to the destination peg, there is an elegant recursive solution:

if n = 1, just move 1 disk from the source peg to the destination peg
otherwise
move n-1 disks from the source peg to the intermediate peg
move 1 disk from the source peg to the destination peg
move n-1 disks from the intermediate peg to the destination peg
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s