Project Euler Problem 2 in Python - Even Fibonacci Numbers (Generators, Recursion, Memoization)

preview_player
Показать описание
Solving Problem 2 of Project Euler in Python with 2 implementations: (i) Generators; and (ii) Memoized recursive function.

Timestamps:
01:08 Generators
02:55 Recursion + Memoization

Notes:
On the inefficiency of the fib function without memoization - an illustration:
fib(100) would call fib(98), which would then call fib(96) so on and so forth, until it reaches the base case of fib(x) where x is less than 2. Each nested call, such as fib(98) and fib(96) above, would also have to evaluate all their nested calls in order to generate an answer.

With memoization:
The memoized fib function "remembers" that it has received a certain argument before, and would simply return the value, rather than going through the whole chain of nested calls.

Let me know if you have any questions!
Рекомендации по теме
welcome to shbcf.ru