| 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