Re:Dynamic Programming vs. Divide-and-Conquer (2018)
by jvanderbot on Sunday April 25, 2021 @12:12PM
(#26933830)
Op's saying (I think) that the difference between brute force recursion and DP ( top down ) is memoization, and that the language / library construct lru_cache will perform that memoization for you.
Its not a fascinating insight. If you can express a problem as a recursive brute force solution and there's a least a little recalculation involved, you're one step from DP. The lru_cache just does that step.
Just google lru_cache
edit: "op"
Re:Dynamic Programming vs. Divide-and-Conquer (2018)
by currymj on Sunday April 25, 2021 @12:29PM
(#26933988)
it is a particular part of the Python 3 standard library. it is one extra line of code to automatically memoize a recursive function.
you just do:
from functools import lru_cache
@lru_cache(maxsize=None)
def brute_recursive_func(x):
...
And you're good to go.
Re:Dynamic Programming vs. Divide-and-Conquer (2018)
by rmk on Sunday April 25, 2021 @02:49PM
(#26935404)
Very nice! I often forget this handy thing during interviews. Good thing to impress your interviewer with :)
I know about lru caches.
Yet, I'm not fully understanding what your implying with your comment.