๐ŸŽ 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

DRY (Don't Repeat Yourself)
A software development principle that aims to reduce code duplication by abstracting common patterns into reusable components.
Factory Pattern
A creational design pattern that provides an interface for creating objects without specifying their exact classes.
SOLID Principles
Five design principles for writing maintainable, flexible object-oriented code: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
Dependency Injection
A design pattern where objects receive their dependencies from external sources rather than creating them internally.
Recursion
A programming technique where a function calls itself to solve a problem by breaking it into smaller subproblems.
Singleton Pattern
A design pattern that restricts a class to a single instance and provides a global point of access to that instance.
View All Programming Concepts Terms โ†’