Alex Rivera | Logout

Should I use recursion or memoization for an algorithm?

Asked 2009-01-26T15:11:28.533
12

If I have a choice to use recursion or memoization to solve a problem which should I use? In other words if they are both viable solutions in that they give the correct output and can be reasonably expressed in the code I'm using, when would I use one over the other?

Edit
Report

1 Answer

3

I believe you might be confusing memoization (which is, as others have noted, an optimization strategy for recursive algorithms) with dynamic programming (which simulates a recursive solution but does not actually use recursion). If that was your question I'd say it would depend on your priorities: high runtime efficiency (dynamic programming) or high readability (memoization, as the recursive solution of the problem is still present in the code).

answered 2009-02-09T23:57:33.830

Your Answer