Article Preview
Buy Now
COLUMN
Memoizing
How to Take Good Notes
Issue: 1.5 (April/May 2003)
Author: Matt Neuburg
Author Bio: Matt Neuburg is the author of
Article Description: No description available.
Article Length (in bytes): 14,238
Starting Page Number: 34
Article Number: 1517
Resource File(s):
1517.zip Updated: 2013-03-11 19:07:56
Related Link(s): None
Excerpt of article text...
The term "memoizing" is not a misspelling of "memorizing," but the two notions are related. Memoizing is a technique that can come in handy in programming situations where you're performing a calculation that has input, and the same input always yields the same result. The motivation for memoizing arises when the calculation is lengthy and is likely to be performed on the same input more than once. Memoizing itself is a cross between simply performing the calculation, on the one hand, and looking up the answer in a table, on the other.
Perhaps before going any further I should pause to point out that a lookup table is itself an important programming technique that is often neglected by beginners -- perhaps because it seems too easy, or too obvious. For example, suppose you had to implement REALbasic's Hex function, which translates a decimal integer to a hex string. What this really boils down to is translating a value between 0 and 15 into a hex digit, so let's concentrate on that. Clearly there are two cases. If the value is between 0 and 9, we can use it as an offset from the ascii value of the character "0". If it's between 10 and 15, we can subtract 10 and use the result as an offset from the ascii value of the character "A".
Hexify By Calculation
Function hexify(i as integer) As string
dim base as integer
...End of Excerpt. Please purchase the magazine to read the full article.