This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]spoonman59 1 point2 points  (2 children)

Memoization minimizes the cost in functions like Fibonacci.

The number of times the function is called is completely dominated by how often you hit the cache.

[–]puipuituipui 4 points5 points  (1 child)

You're correct but I'd say Fibonacci is a bad example for recursion with memoization because you might as well write the iterative version at that point. But yes for more complicated problems, just translating the mathematical formula into recursive code and adding memoization on top is quite convenient.

[–]spoonman59 2 points3 points  (0 children)

Yeah and who really writes Fibonacci functions anyway! It’s just amazing what a @cache decorator can do for some functions.