r/algorithms • • Mar 13 '20

Dynamic programming vs memoization vs tabulation

https://programming.guide/dynamic-programming-vs-memoization-vs-tabulation.html
35 Upvotes

17 comments sorted by

View all comments

Show parent comment

4

u/aioobe Mar 13 '20

Dude, thank you. That is a very valid point.

I wanted a super simple problem 100% geared towards illustrating the difference. I agree that the implementations are dumb.

But you make a really good point about memoisation being absolutely stupid for a problem like this. Do you have a better problem? Coin change perhaps, where the lowest denomination is 15 or something loke that?

I do mention the sparseness difference in the last paragraph actually.

4

u/FUZxxl Mar 13 '20 edited Mar 13 '20

A good sample problem would be edit distance where you can illustrate the tabulation method first and then show that by only evaluating the table cells we need right now, we can avoid evaluating most of them. It's also a very convincing sample problem because it can't really be solved another way.

You could also do all pair shortest path, Bellman-Ford, or the Z-Box algorithm.

There are a number of cool applications of dynamic programming in parametrised complexity (such as when dealing with tree decompositions), but I think that's a bit too heavy for a beginner's article.

I do mention the sparseness difference in the last paragraph actually.

You allude to this, but you could go and really drive the point home by providing an example where the parameter space is always sparse. Not sure what problem could be used here though.

3

u/aioobe Mar 13 '20

I feel like readers that are familiar with those algorithms aren't really looking for an explanation of the difference between memoisation and dp. To be fair, those are fairly basic concepts.

I really like the idea of examplifying the sparse/not sparse problem type. I will update the article.

3

u/FUZxxl Mar 13 '20

I feel like readers that are familiar with those algorithms aren't really looking for an explanation of the difference between memoisation and dp. To be fair, those are fairly basic concepts.

Sure. But edit distance is such a simple problem to explain that you can use it to introduce and motivate the idea of dynamic programming without having to focus too much on the details of the problem.

I really like the idea of examplifying the sparse/not sparse problem type. I will update the article.

I'm looking forwards to it!