Última actividad 1727095887

Ever ask the same question over and over? Annoying, right? That’s what your computer thinks too.

Revisión b46a3c7a169e5de174952a5ee1f7b4c77784adef

memoization.py Sin formato
1# example of memoization in pythong for fibonacci
2
3# Memoization: Let’s Be Efficient, Shall We?
4# Ever ask the same question over and over? Annoying, right? That’s what your computer thinks too. Memoization fixes this by storing results so you don’t have to repeat expensive calculations.
5def fib(n, memo={}):
6 if n in memo:
7 return memo[n]
8 if n < 2:
9 return n
10 memo[n] = fib(n - 1, memo) + fib(n - 2, memo)
11 return memo[n]
12
13fib(100)
14
15# 354224848179261915075
16