1

Memoization is definitely a powerful technique.

But Dynamic Programming is slightly better IMO, since it does not involve the memory strain (in a recursive program, the parameters occupy memory and this memory increases as we go deeper into the recursion). But speed-wise, both are pretty equal.

But definitely memoization is a lot more straight-forward than Dynamic Programming.

My question: Is it somehow possible to use memoization without the memory constraint ?

Robert Harvey
201k55 gold badges470 silver badges682 bronze badges
asked Feb 25, 2014 at 9:00
4
  • 1
    you can combine dynamic programming and memoization Commented Feb 25, 2014 at 9:01
  • @ratchet freak: How ? What is the use ? Commented Feb 25, 2014 at 9:03
  • 4
    DP is basically equivalent to memoization. The difference is that in DP, you generate the cache in a specific way and are aware of what cache entries are used when (compare a memoized factorial with O(n) memory, and the DP factorial with O(1) memory). Effectively, recursion (with memoization) is a top-down strategy, whereas DP constructs a solution bottom-up: the same, but from different directions. Commented Feb 25, 2014 at 10:21
  • To expand upon amon's response, see SO: Dynamic programming and memoization: bottom-up vs top-down approaches for a more in depth explanation of the difference between Memoization and DP. Commented Mar 27, 2014 at 18:27

1 Answer 1

2

You can reduce the amount of memory used for memoization by using a "Least Recently Used" cache (with limited maximum size) for the memoized values. How well this works depends heavily on the problem, the function you are going to memoize and the choice of the cache size. But I guess for a problem where DP works well, there is a good chance that function values needed in a first stage of a calculation won't be needed any more some stages later, so the LRU strategy will free the resources for these values automatically.

answered Feb 25, 2014 at 15:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.