Can you point me to some dynamic programming problem statements where bottom up is more beneficial than top down? (i.e. simple DP works more naturally but memoization would be harder to implement?)
I find recursion with memoization much easier, and want to solve problems where bottom up is a better/perhaps only feasible approach.
I understand that theoretically both are equivalent, so even something like ease of implementation would count as a benefit.
In the top-down DP solution we defined the states and subproblems starting from the problem that we want to solve. That is, having all objects available and a knapsack of capacity C. In bottom-up DP we will write an iterative solution to compute the value of every state.
Bottom-up DP is faster than top-down since it doesn't involve any function calls. It completely depends on the table entries while in top-down DP it requires function calls and thereby causing an implicit stack formation.
The two main approaches to dynamic programming are memoization (top-down approach) and tabulation (bottom-up approach). Memoization = Recursion + Caching. Recursion is expensive both in processor time and memory space. In the tabulation approach to DP, we solve all sub-problems and store their results on a matrix.
You will apply bottom up with memoization OR top down recursion with memoization depending on the problem at hand .
For example, if you have to find the minimum weight independent path of a path graph, you will use the bottom up approach as you have to solve all the subproblems that are possible.
But if you have to solve the knapsack problem , you may want to use recursive top down with memoization as you have to solve a limited number of subproblems. Approaching the knapsack problem bottom up will cause the algo to solve a lot of redundant problems that are not used in the original subproblem.
Two things to consider when deciding which algorithm to use
fibonacci(n) = fibonacci(n-1) + fibonacci(n-2)
, we only need to store the past two calculationsThat being said, bottom-up is not always the best choice, I will try to illustrate with examples:
nmlog(nm)
pre-processing time before DPIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With