Representational Choice

Representational Choices
The Towers of Hanoi Problem
We will consider five
Representational Choice for the
Towers of Hanoi Problem
1.
2.
3.
4.
5.
Graphical
Extensional (Table)
Extensional (Descriptive)
Recurrence Relation (intensional)
Pseudo-code (intensional)
1. Graphical Representation
(Start State)
Graphical Representation
(Goal State)
Graphical Representation
(Step 1)
Graphical Representation
(Step Two)
Graphical Representation
(Step 3)
Graphical Representation (Step 4:
Isolate “Mr. Big”)
Graphical Representation (Step 5:
Unravel from Peg B)
Graphical Representation (Step 6:
Assemble on Peg C)
Graphical Representation (Step 7:
Finish Assembly on Peg C)
Table Representation
No.
Moves to Moves from “Mr.
Disks Temp Peg Temp to
Big” to
Goal
Goal
Total
Number
Moves
1
2
3
0
1
3
0
1
3
1
1
1
1
3
7
4
7
7
1
15
5
15
15
1
31
6
31
31
1
63
7
63
63
1
127
Extensional (Descriptive)
Solution
• Attachment Towers Image 2: Extensional Solution
• For any number of disks, N, if the main goal is to move those N
disks from Peg A to Peg C, then you can complete the following
steps:
• Move N-1 disks to an intermediary peg (B), which takes 2(N-1) – 1
moves (e.g., for three disks, move two disks (2^2 – 1 moves = 3
moves) to peg B).
• Move the biggest disk from Peg A to Peg C (the Goal).
• Move the N-1 disks from Peg B to Peg C (the Goal, which takes
three more moves).
• In total, you need 7 moves for 3 discs, 15 moves for 4 disks, 31
moves (15 + 15 + 1) for 5 disks, 63 moves (31 + 31 + 1) for 6 disks,
etc.
Representational Choices (4
Recurrence Relation (Intensional)
• T(1) = 1
• T(N) = 2 T (N-1) + 1
• Which has solution T(N) = 2^N -1.
Representational Choices: PseudoCode (intensional, RECURSIVE)
•
•
•
•
•
•
•
•
•
n is the number of disks
Start is the start peg
int is the intermediate peg
Dest is the goal or destination peg
TOH (n, Start, Int, Dest)
If n = 1 then move disk from Start to Dest
Else TOH(n-1, Start, Dest, Int)
TOH(1, Start, Int, Dest)
TOH(n-1, Int, Start, Dest)
SUMMARY
• Note that each of these intentional
representations is also an example of
problem reduction. A problem that
seemed large and complex has been
broken down into smaller, manageable
problems whose solution can be
carried out and
is understandable to the problemsolver.