
Dynamic programming optimizes recursive problems by storing results for overlapping subproblems, using top-down memorisation or bottom-up construction, and reducing time from exponential to polynomial through optimal substructure.
Explore how the knapsack problem models choosing items to maximize value under a weight limit, using dynamic programming with 0/1 and unbounded variations and a table-based solution.
Explore dynamic programming with Floyd's algorithm to compute shortest paths in a weighted graph, initializing zeros on the diagonal, infinity elsewhere, and updating distances with a minimum formula.
Learn to build a Huffman code by sorting characters by probability, repeatedly combining the two smallest, forming a binary tree, deriving code words, and calculating the maximum bit lengths.
Explore Prim's algorithm as it builds a minimum spanning tree by adding the smallest connecting edge. The lecture demonstrates this on a graph with A, B, C, D, totaling 15.
Sort edges by weight and add them if they do not form a cycle, as Kruskal's algorithm builds a spanning tree and sums the total weight.
Explore the multistage graph and the forward approach to dynamic programming, deriving the minimum cost path and identifying broken edges. Introduce the simplex algorithm.
Explore modeling a multistage graph with a source and destination and solve for minimum-cost path using a dynamic programming recurrence. Compute each stage's cost plus the next stage's optimal cost.
Explore the longest common subsequence problem and its dynamic programming solution. Build a DP table to compute the LCS length for two strings using the recurrence.
Learn to implement the longest common subsequence using dynamic programming in Python, input strings x and y, and print the lcs length.
Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics.
In both contexts it refers to simplifying a complicated problem by breaking it down into simpler sub-problems in a recursive manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do often break apart recursively. Likewise, in computer science, if a problem can be solved optimally by breaking it into sub-problems and then recursively finding the optimal solutions to the sub-problems, then it is said to have optimal substructure.
If sub-problems can be nested recursively inside larger problems, so that dynamic programming methods are applicable, then there is a relation between the value of the larger problem and the values of the sub-problems.[1] In the optimization literature this relationship is called the Bellman equation.Mathematical optimization
In terms of mathematical optimization, dynamic programming usually refers to simplifying a decision by breaking it down into a sequence of decision steps over time. This is done by defining a sequence of value functionsV1, V2, ..., Vn taking y as an argument representing the state of the system at times i from 1 to n. The definition of Vn(y) is the value obtained in state y at the last time n. The values Vi at earlier times i = n −1, n − 2, ..., 2, 1 can be found by working backwards, using a recursive relationship called the Bellman equation. For i = 2, ..., n, Vi−1 at any state y is calculated from Vi by maximizing a simple function (usually the sum) of the gain from a decision at time i − 1 and the function Vi at the new state of the system if this decision is made. Since Vi has already been calculated for the needed states, the above operation yields Vi−1 for those states. Finally, V1 at the initial state of the system is the value of the optimal solution. The optimal values of the decision variables can be recovered, one by one, by tracking back the calculations already performed.