Wednesday, November 27, 2013

Memory Model (The tour of Anne Hoy; Assignment 1)

The tour of Anne Hoy is much like the tower of Hanoi with the difference of using four pegs instead of three pegs. Starting with the assignment we have the knowledge of the algorithm for the tower of Hanoi. So the tricky part of the assignment is not implementing on how to move the disk(cheese), the tricky part is to implement the splitting part of the first peg.

Equation of TOAH

So basically find the optimal i of M(n). The solution is to pick different i and try them all to see which one is fit for n. If you didn't save the i for that particular n, every time it run to find the i for (n+1), it need to find i for n again, which is not very efficient. So the solution is memory model. It stores every i that had run before. It also called memorization. There is this function that Danny Heap wrote that you only need to input the function that you want to memorize; it will record the output for future use. With the additional advantage that it will secure the table you need to memorize, because only the function can access the table.


I can see why Danny didn't teach us the use memorization before the assignment. It will only confuse us, such as inputting a function as a parameter. After knowing how Python works around its object with namespace, this all makes sense.

No comments:

Post a Comment