Tower of Hanoi for information systems students

I teach Introduction to Programming to students in our „WIN“ information systems bachelor study programme. When introducing the principle of recursion, it seems to be inevitable to talk about the Tower of Hanoi. A number of disks has to be moved from one of three rods to another. Because you can only move one disk at a time and because only smaller disks can be put on larger disks, you need three rods to move more than one disk from one rod to another. To be better able to demonstrate how the Tower of Hanoi works, I decided to order buy a wooden version of the game.

tower-of-hanoi-boxThe least expensive option was to buy from a shop in Singapore. I knew that I would get a small version, and after a couple of weeks a package arrived in the mail. For customs clearance, the field „Detailed description of contents“ was labelled with „1x Cell Phone Accessories“. I wondered what had went wrong. After I had opened the package, I spotted a person on the packaging. For what reason ever the designer of the box had decided to a picture of somebody in a business suit holding a mobile phone. Maybe the game is intended for business travellers that play Tower of Hanoi while waiting for a connection?

Next time I teach the class I will frame the underlying problem of the Tower of Hanoi differently so that it is closer to our information systems students.

Instead of moving disks between rods, think of the following problem:

  • You have three warehouses that you can use to store goods.
  • In the beginning, all goods are in the first warehouse.
  • In the end, all goods should be in the third warehouse.
  • You can move one item at a time, because your transportation capacity is limited.
  • Access to goods in a warehouse is limited to the item that was stored last (last-in-first-out)
  • Goods are perishable, therefore you need to store goods in the right order, i.e. you want to have the more endangered goods to be more easily accessible than the less (corresponds to small disk on large disk)

Recursion is a concept that seems to be hard for many first year students, so we will see if it works better when taught with an example closer to the topics of the study programme.

About Author: Hanno Langweg

Comments are closed.

Search