๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Programming Concepts Intermediate

What is Memoization?

An optimization technique that caches function results for given inputs, avoiding redundant computations for repeated calls.

Memoization stores the results of expensive function calls and returns the cached result when the same inputs occur again. In Python: @functools.lru_cache decorates a function to automatically memoize results.

Memoization is key to dynamic programming, where overlapping subproblems would otherwise cause exponential time complexity. Classic examples include Fibonacci numbers (O(2^n) โ†’ O(n)), pathfinding, and string matching. It trades memory for speed.

Related Terms

Composition over Inheritance
A design principle favoring object composition (has-a relationships) over class inheritance (is-a relationships) for code reuse.
Stack
A data structure that follows Last-In-First-Out (LIFO) ordering, where elements are added and removed from the same end (top).
Singleton Pattern
A design pattern that restricts a class to a single instance and provides a global point of access to that instance.
Concurrency
The ability of a program to manage multiple tasks that can make progress during overlapping time periods.
Code Smell
A surface indication in code that usually corresponds to a deeper problem in the system, suggesting the need for refactoring.
Factory Pattern
A creational design pattern that provides an interface for creating objects without specifying their exact classes.
View All Programming Concepts Terms โ†’