Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems andstores the results of subproblems to avoid computing the same results again. Following are the two main properties of a problem thatsuggest that the given problem can be solved using Dynamic programming.
1) Overlapping Subproblems: Like Divide and Conquer, Dynamic Programming combines solutions to sub-problems. Dynamic Programming is mainly used when solutions of same subproblems are called again and again. In dynamic programming, computed solutions to subproblems are stored so that these don’t have to be recomputed. There are following two different ways to store the values so that these values can be reused.
a) Memoization: The memoized program for a problem is similar to therecursive version with a small modification that itlooks into a lookup table before computing solutions. We initialize a lookup array with all initial values as NIL. Whenever we need solution to a subproblem, we first look into the lookup table. If the value wanted is there then we just return the value, otherwise we calculate the value and put the result inlookup table so that it can be reused later.
b) Tabulation: The tabulated program for a given problembuilds a table iteratively and returns the wanted entry from table.
Both tabulated and Memoized store the solutions of subproblems. In Memoized version, table is filled on demand while in tabulated version, it is filled iteratively. Unlike the tabulated version, all entries of the lookup table are not necessarily filled in memoized version. So how should us choose between Memoization and Tabulation?
2) Optimal Substructure: A given problems has Optimal Substructure
Property if optimal solution of the given problem can be obtained by using optimal solutions of its subproblems.
动态规划是一种算法范式,通过分解复杂问题为子问题并存储子问题结果来避免重复计算。本文阐述了动态规划解决复杂问题的核心特性:重叠子问题和最优子结构。它通过两种主要方式存储子问题结果:递归记忆化和表格填充,以提高效率。了解这些概念对于深入理解动态规划及其应用至关重要。
2126

被折叠的 条评论
为什么被折叠?



