SlideServe
Menu
Préférences
© SlideServe · v2026

Lecture 6: Dynamic Programming

timothy-davidson avatar
14 diapositives · 357 Views · Nov 29, 2014

Lecture 6: Dynamic Programming. 0/1 Knapsack     Making Change (any coin set). What is Dynamic Programming?.

Lecture 6: Dynamic Programming - slide 1
01 / 14Lecture 6: Dynamic Programming
1 / 17

Télécharger la présentation

Lecture 6: Dynamic Programming
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Lecture 6: Dynamic Programming 0/1 Knapsack    Making Change (any coin set)

  2. What is Dynamic Programming? Dynamic programming is similar to divide-and-conquer in that the problem is broken down into smaller subproblems. In this approach we solve the small instances first, save the results, and look them up later when we needed, rather than recompute them. Dynamic programming can sometimes provide an efficient solution to a problem for which divide-and-conquer produces an exponential run-time. Occasionally we find that we do not need to save all subproblem solutions. In these cases we can revise the algorithm greatly reducing the memory space requirements for the algorithm. • 1. establish a recursive property that gives the solution to an instance of the problem • 2. solve instances of the problem in a bottom-up fashion starting with the smaller instances first.

  3. Binomial Theorem The binomial theorem gives a closed-form expression for the coefficient of any term in the expansion of a binomial raised to the nth power. (a+b)0 = 1 (a+b)1 = a+b (a+b)2 = a2+2ab+b2 (a+b)3 = a3+3a2b+3ab2+b3 (a+b)4 = a4+4a3b+6a2b2+4ab3+b4

  4. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Counting Combinations & Pascal's Triangle The binomial coefficient is also the number of combinations of n items taken k at a time, sometimes called n-choose-k.

  5. Binomial Coefficient D&C Version function bin(n,k : integer) return integer is begin if k=0 or k=n then return 1; else return bin(n-1,k-1) + bin(n-1,k); end if; end bin; This version of bin requires that the subproblems are recalculated many times for each recursive call.

  6. Binomial Coefficient Dynamic Programming function bin2(n,k:integer) return integer s B : array(0..n,o..k) of integer; begin for i in 0..n loop for j in 0..minimum(i,k) loop if j=0 or j=i then B(i,j)=1; else B(i,j):=B(i-1,j-1) + B(i-1,j); endif; end loop; end loop; return B(n,k); end bin2; In bin2 the smallest instances of the problem are solved first and then used to compute values for the larger subproblems. Compare the computational complexities of bin and bin2.

  7. V1 1 2 V5 5 3 V2 2 6 1 1 V3 V4 1 Floyd's Algorithm for Shortest Paths procedure floyd(W,D:matype) is begin D:=W; for k in 1..n loop for i in 1..n loop for j in 1..n loop D(i,j):=min(D(i,j),D(i,k)+D(k,j)); end loop; end loop; end loop; end floyd; 1 2 3 4 5 1 0 2 - - - 2 3 0 6 - - 3 - - 0 - 1 4 2 - 1 0 1 5 1 - - - 0 Floyd's algorithm is very simple to implement. The fact that it works at all is not obvious. Be sure to work through the proof of algorithm correctness in the text.

  8. Dynamic Programming - The Coin Changing Problem Northeastern University - Javed A. Aslam - CSG713 Advanced Algorithms

  9. Defining the Recurrence Relation Northeastern University - Javed A. Aslam - CSG713 Advanced Algorithms

  10. Implementing the Bottom-Up Algorithm Northeastern University - Javed A. Aslam - CSG713 Advanced Algorithms

  11. Generating an Optimal Solution Northeastern University - Javed A. Aslam - CSG713 Advanced Algorithms

  12. Algorithm/Program Analysis Northeastern University - Javed A. Aslam - CSG713 Advanced Algorithms

  13. Summary Dynamic Programming solves problems that can be expressed as recurrence relations Rather than recursive programming (e.g. D&C) DynPro solves these problem in a bottom-up fashion It is good practice to compare complexity for D&C vs DynPro DynPro works when sub-problems are solved by sub-solutions. That is, optimal partial solutions are parts of the optimal solution.