Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Last active October 16, 2019 18:00
Show Gist options
  • Save huzaifaarain/0d0d003205092351277af8e2a6fd7833 to your computer and use it in GitHub Desktop.
Save huzaifaarain/0d0d003205092351277af8e2a6fd7833 to your computer and use it in GitHub Desktop.
What is Dynamic Programming ? How it works ? Its Applications & Problems Algorithms

Dynamic Programming

Dynamic programming, like the divide-and-conquer method, solves problems by combining the solutions to subproblems. (“Programming” in this context refers to a tabular method, not to writing computer code.) Divide-and-conquer algorithms partition the problem into disjoint subproblems, solve the subproblems recursively, and then combine their solutions to solve the original problem. In contrast, dynamic programming applies when the subproblems overlap—that is, when subproblems share subsubproblems. In this context, a divide-and-conquer algorithm does more work than necessary, repeatedly solving the common subsubproblems. A dynamic-programming algorithm solves each subsubproblem just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer every time it solves each subsubproblem. We typically apply dynamic programming to optimization problems. Such problems can have many possible solutions. Each solution has a value, and we wish to find a solution with the optimal (minimum or maximum) value. We call such a solution an optimal solution to the problem, as opposed to the optimal solution, since there may be several solutions that achieve the optimal value. When developing a dynamic-programming algorithm, we follow a sequence of four steps:

  1. Characterize the structure of an optimal solution
  2. Recursively define the value of an optimal solution
  3. Compute the value of an optimal solution, typically in a bottom-up fashion
  4. Construct an optimal solution from computed information

Steps 1–3 form the basis of a dynamic-programming solution to a problem. If we need only the value of an optimal solution, and not the solution itself, then we can omit step 4. When we do perform step 4, we sometimes maintain additional information during step 3 so that we can easily construct an optimal solution.

Applications of Dynamic Programming

  1. 0/1 knapsack problem
  2. Mathematical optimization problem
  3. All pair Shortest path problem
  4. Reliability design problem
  5. Longest common subsequence (LCS)
  6. Flight control and robotics control
  7. Time sharing: It schedules the job to maximize CPU usage
  8. Traveling Salesman Problem
  9. Multi stage graph and many more.

In fact every problem which compute the same subproblems or subsubproblems more than once can be done using dynamic programming.

Dynamic Programming Algorithms

Fibonacci Series

Rod Cutting Using Dynamic Programming Part 1

Rod Cutting Using Dynamic Programming Part 2

Citations

Chapter 15 Dynamic Programming. Introduction to Algorithms, 3rd Edition by Cormen, Leiserson, Rivest & Stein (CLRS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment