Memoization is a programming technique where the results of expensive function calls are stored and reused, preventing redundant computations and improving performance.
Sample Memoization
import java.util.HashMap;
import java.util.Map;
public class Fibonacci {
private static Map<Integer, Integer> memory = new HashMap<>();
public static void main(String[] args) {
int result = calculateFibonacci(5);
System.out.println("Fibonacci number at position 5 is: " + result);
}
private static int calculateFibonacci(int n) {
if (n <= 1) { return n;}
if (memory.containsKey(n)) { return memory.get(n); }
int fib = calculateFibonacci(n - 1) + calculateFibonacci(n - 2);
memory.put(n, fib);
return fib;
}
}
Clearly defined by the explanation and exemplified by the example, this technique involves creating a cache for results and memorizing values, utilizing memory. In everyday language, this behavior is also referred to as memorization.The omission of the "r" in the term is simply unnecessary and can make the naming definition vague.
I am wondering why this technique is called "memoization" instead of "memorization"?
Exactly because it's NOT "memorization" and has a specific meaning beyond simply memorizing something. I.e., you're memorizing something for a specific purpose (a performance benefit, not simply storing information).
According to Wikipedia, on memoization (emphasis mine):
While memorization is generically