📄 memoize.html
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD W3 HTML 2.0//EN">
<HTML lang="en-US">
<HEAD>
<TITLE>memoization</TITLE>
<META name="description"
content="Definition of memoization,
possibly with links to more information and implementations.">
<META name="keywords" content="memoization">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<H1>memoization</H1>
<P>
(algorithmic technique)
<P>
<strong>Definition:</strong>
An algorithmic technique which saves (memoizes) a computed answer for later reuse, rather than recomputing the answer.
<P><em>Note:
The term comes from "memo": "A short note written as a reminder." [The American Heritage Dictionary of the English Language, © 1970, American Heritage Publishing] <P> A naive program to compute <a href="fibonacnmbrs.html" tppabs="http://hissa.nist.gov/dads/HTML/fibonacnmbrs.html"><em>Fibonacci numbers</em></a> is <pre> fib(n) {<br> if n is 1 or 2, return 1;<br> return fib(n-1) + fib(n-2);<br> } </pre> Because fib() is recomputed over and over for the same argument, run time for the above is <a href="omegaCapital.html" tppabs="http://hissa.nist.gov/dads/HTML/omegaCapital.html"><em> <img src="Omega-1.gif" tppabs="http://hissa.nist.gov/dads/HTML/Images/Omega.gif" border=0 height=10 width=9 alt="Capital Omega"></em></a>(1.6<sup>n</sup>). If instead we memoize (save) the value of fib(n) the first time we compute it, the run time is <a href="theta.html" tppabs="http://hissa.nist.gov/dads/HTML/theta.html"><em> <img src="Theta-1.gif" tppabs="http://hissa.nist.gov/dads/HTML/Images/Theta.gif" border=0 height=10 width=8 alt="Capital Theta"></em></a>(n). <pre> allocate array for memo;<br> initialize memo[1] and memo[2] to 1;<br> <br> fib(n) {<br> if memo[n] is not zero, return memo[n];<br> memo[n] = fib(n-1) + fib(n-2);<br> return memo[n];<br> } </pre> <P> Of course, computing Fibonacci numbers can be easily done in constant time (see <a href="fibonacnmbrs.html" tppabs="http://hissa.nist.gov/dads/HTML/fibonacnmbrs.html"><em>Fibonacci numbers</em></a>), but this illustrates the technique.</em>
<P>Author: <a href="terms.html#authorPEB" tppabs="http://hissa.nist.gov/dads/terms.html#authorPEB">PEB</a>
<hr>
Go to the
<A HREF="terms.html" tppabs="http://hissa.nist.gov/dads/terms.html">Algorithms, Data Structures, and Problems</A>
home page.
<hr>
If you have suggestions, corrections, or comments, please get in touch
with
<a href="javascript:if(confirm('http://hissa.nist.gov/~black/black.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://hissa.nist.gov/~black/black.html'" tppabs="http://hissa.nist.gov/~black/black.html">Paul E. Black</a>
(<a href="mailto:paul.black@nist.gov">paul.black@nist.gov</a>).
<p>
Entry modified Fri Jan 7 09:28:38 2000.<BR>
HTML page formatted Fri Jan 7 09:48:14 2000.
<P>
This page's URL is
<A href="memoize.html" tppabs="http://hissa.nist.gov/dads/HTML/memoize.html">http://hissa.nist.gov/dads/HTML/memoize.html</A>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -