MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / rec_fn_memoized

Function rec_fn_memoized

maths/fibonacci.py:190–196  ·  view source on GitHub ↗
(num: int)

Source from the content-addressed store, hash-verified

188 cache: dict[int, int] = {0: 0, 1: 1, 2: 1} # Prefilled cache
189
190 def rec_fn_memoized(num: int) -> int:
191 if num in cache:
192 return cache[num]
193
194 value = rec_fn_memoized(num - 1) + rec_fn_memoized(num - 2)
195 cache[num] = value
196 return value
197
198 return [rec_fn_memoized(i) for i in range(n + 1)]
199

Callers 1

fib_memoizationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected