mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update README.md
This commit is contained in:
parent
78f2ab992e
commit
16d09b5b0d
@ -50,6 +50,18 @@ def reverse(s):
|
|||||||
* memoization is an optimization technique that avoids recursion's duplicate calculations.
|
* memoization is an optimization technique that avoids recursion's duplicate calculations.
|
||||||
* it's primarily used to speed up code by storing the intermediate results in a cache so that it can be reused later.
|
* it's primarily used to speed up code by storing the intermediate results in a cache so that it can be reused later.
|
||||||
* for example, a hash table can be used as a cache and should be passed along each subroutine call.
|
* for example, a hash table can be used as a cache and should be passed along each subroutine call.
|
||||||
|
* classical examples are fibonnaci and the "climbing stairs" problem:
|
||||||
|
|
||||||
|
```python
|
||||||
|
cache = {1: 1, 0: 1}
|
||||||
|
|
||||||
|
def climbing_stairs(n) -> int:
|
||||||
|
|
||||||
|
if n not in cache:
|
||||||
|
cache[n] = climbing_stairs(n-1) + climbing_stairs(n-2)
|
||||||
|
|
||||||
|
return cache[n]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user