The usual criteria used to decide if a problem can be solved using dynamic programming is (1) if it has optimal sub-problems and (2) if it has overlapping sub-problems. Does the word "optimal" mean that DP can only be used to solve optimization problems? Otherwise, it would make more sense to write (1) as "if it can be decomposed in sub-problems" (i.e. it is recursive). Obviously, this definition includes optimization problems with optimal sub-problems.
-
1$\begingroup$ Here is an example of a decision problem amenable to dynamic programming: is the edit distance between $x,y$ at most $d$? $\endgroup$Yuval Filmus– Yuval Filmus2019-12-02 14:56:02 +00:00Commented Dec 2, 2019 at 14:56
-
2$\begingroup$ Problems involving counting something (e.g., the number of ways of building a $3\times n$ wall out of dominos) can often be solved with what I'd call dynamic programming. More discussion here: cs.stackexchange.com/questions/79664/… $\endgroup$j_random_hacker– j_random_hacker2019-12-03 00:49:56 +00:00Commented Dec 3, 2019 at 0:49
-
$\begingroup$ I wonder if problems "count ways to do X" aren't always equivalent to "find quantity optimizing Y". I can't think of Y for say, Fibonacci numbers, but that's not the same as saying no one can. $\endgroup$Matthew C– Matthew C2019-12-06 16:40:32 +00:00Commented Dec 6, 2019 at 16:40
1 Answer
Dynamic Programming can be used to solve a problem as long as the problem has a recursive substructure and the sub-structural problems are overlapping. So, as long as a problem has the two properties, DP can be used for solving it. Problems with these properties are definitely not restricted to only optimization problems. So, yes.
Here are some good examples of non-optimization problems which can be solved quickly using DP:
Counting the number of increasing subsequences in a given sequence
If you forget everything, calculating upto the first $n$ Fibonacci Numbers using its recurrence relation can be done using Dynamic Programming.
-
$\begingroup$ Great answer, welcome to the site! $\endgroup$Joey Eremondi– Joey Eremondi2019-12-06 18:12:22 +00:00Commented Dec 6, 2019 at 18:12
-
$\begingroup$ Thanks for the appreciation! :D $\endgroup$Arkajyoti Banerjee– Arkajyoti Banerjee2019-12-06 18:13:19 +00:00Commented Dec 6, 2019 at 18:13
-
$\begingroup$ I'm confused why you think the coin change problem is not an optimization problem. It actually has a well-defined objective function that we are seeking to minimize (the number of coins) with a clear set of constraints (that add up to a given amount). $\endgroup$Amelio Vazquez-Reina– Amelio Vazquez-Reina2020-04-04 23:49:36 +00:00Commented Apr 4, 2020 at 23:49
-
1$\begingroup$ @AmelioVazquez-Reina By the Coin Change Problem, I mean the problem that asks us to count the number of ways of making an amount using some given denominations, and not minimize the number of coins used to make the amount. The link in the previous version of this answer leads to the latter. I've updated the link. $\endgroup$Arkajyoti Banerjee– Arkajyoti Banerjee2020-04-05 08:30:32 +00:00Commented Apr 5, 2020 at 8:30
-
$\begingroup$ Thanks @ArkajyotiBanerjee, yes, the prev. link had confused me +1. $\endgroup$Amelio Vazquez-Reina– Amelio Vazquez-Reina2020-04-13 16:37:26 +00:00Commented Apr 13, 2020 at 16:37