Anonymous user
Category:Memoization: Difference between revisions
m
Just clarifying a little and making some things prettier
m (Just clarifying a little and making some things prettier) |
|||
Line 1:
Memoization is a method used to reduce function calls in recursive functions or other functions that are called very frequently. The basic idea behind memoizing is to store results for new sets of inputs (typically in a key-value style) so that the function will not have to re-compute those results later when the same inputs are used (either in another direct function call or a subsequent recursive call).
Functions which can be memoized are ones that give the same answer for a set of inputs each time those inputs are used. [[Fibonacci sequence|Fibonacci number functions]] are often memoized to reduce their call trees and calculation times over time. The basic operation of a memoized function would look something like this:
Line 12:
Some programs may negate the condition in the "if" and swap the operations.
The overall benefit is that a function frequently called with the same set of inputs can save time by remembering the answer after computing it once
[[Category:Classic CS problems and programs]]
|