# Chapter 5 Dynamic Programming

• View
39

• Category

## Documents

Embed Size (px)

DESCRIPTION

Chapter 5 Dynamic Programming. 2001 년 5 월 24 일 충북대학교 알고리즘연구실. Dynamic Programming. Used when the solution of a problem is a result of a sequence of decisions Example Knapsack Shortest path Optimal merge patterns. 5.3 All pairs shortest paths. G(V,E) : A directed graph with n vertices - PowerPoint PPT Presentation

### Text of Chapter 5 Dynamic Programming

• Chapter 5Dynamic Programming2001 5 24

• Dynamic ProgrammingUsed when the solution of a problem is a result of a sequence of decisionsExampleKnapsackShortest pathOptimal merge patterns

• 5.3 All pairs shortest pathsG(V,E) : A directed graph with n vertices

Ak(i,j) : Length of shortest path from i to j going through no vertex of index greater than kA(i,j) = min{min{Ak-1(i,k) + Ak-1(k,j)},cost(i,j)}Ak (i,j) = Ak-1(i,k) + Ak-1(k,j)Ak (i,j) = min{Ak-1(i,j),Ak-1(i,k) + Ak-1(k,j)},k>=1C(i,j) = 0, 1

• 5.3 All pairs shortest pathsFigure 5.5 Graph with negative cycle12311-2

• 5.3 All pairs shortest pathsProgram 5.3 Function to compute lengths of shortest paths

• 5.3 All pairs shortest pathsFigure 5.6 Directed Graph and associated matrices

• 5.4 Single-source shortest paths:General weightsdist[u] = cost[v][u]distl[u] = length of a shortest path from the source vertex V to vertex U under the constraint that the shortest path contains at most L edgesdistk[u] = min(distk-1[u],min(distk-1[i] + cost[i][u])),2
• 5.4 Single-source shortest paths:General weightsFigure 5.10 Shortest paths with negative edge lengths

• 5.4 Single-source shortest paths:General weightsProgram 5.4 Bellman and Ford algorithm to compute shortest paths

• 5.5 Optimal binary search treesDefinitionA binary search tree TAll identifies in the Tleft < TrootAll identifies in the Tright < TrootThe left and right subtres of T are also BSTa1 < a2 < < anTi,j : OBST for ai+1,,ajCi,j : cost for Ti,jRi,j : root of Ti,jWeight of Ti,j : Wi,j = Qi +

• 5.5 Optimal binary search treesP(i) : probability Search(a(i))Q(i) : probability search (a(i) < x < a(i+1)) : Probability of an unsuccessful search

Internal nodeExternal node(5.9)

• Optimal Binary Search TreeCost of the search Tree p(k)+cost(l)+cost(r)+w(0,k-1)+w(k,n)c(0, n) = min{c(0, k-1) + c(k, n) +p(k) +w(0, k-1)+w(k, n)} c(i, j) = min{c(i, k-1), c(k, j)+p(k) + w(i,k-1)+w(k,j)}C(i,j) = min{c(i,k-1)+c(k,j)} + w(i,j)

• 5.5 Optimal binary search treesFigure 5.12 Two possible binary search trees

• 5.5 Optimal binary search treesFigure 5.13 Binary search trees of Figure 5.12 with external nodes added

• 5.5 Optimal binary search trees

• 5.5 Optimal binary search trees

• 5.5 Optimal binary search treesFigure 5.16 Computation of c(0,4), w(0,4), and r(0,4)

• 5.8 Reliability designSolve a problem with a multiplicative optimization functionSeveral devices are connected in seriesri be the reliability of device DiReliability of the entire systemDuplicate : multiple copies of the same device type are connected in parallel use switching circuits

• 5.8 Reliability designFigure 5.19 n devices Di, 1
• Multiple copies stage in contain mi copies of Di P(all mi malfunction) = (1-ri)mi Reliability of stage i =1-(1-ri)mi

• 5.8 Reliability designMaximum allowable cost of the systemMaximize Subject to Mi >=1 and integer, 1
• 5.9 The traveling salesperson problem : n mail pickupn+1 vertex graph Edge distance from i to jTour of minimum costPermutation problemn! different permutation of n object while there are 2n different subset of n object n! > O(2n)

• 5.9 The traveling salesperson problemTour : simple path that starts and ends at vertex 1Every tour : edge for some k v-{1} each Optimal tour : path(k,1)Shortest k to 1 path all the vertices in V-{1,k}Let g(i,s) be the length of a shortest path starting at vertex i, going through all vertices in S and terminating at vertex 1

• 5.9 The traveling salesperson problemFigure 5.21 Directed graph and edge length matrix c

• 5.9 The traveling salesperson problemThus g(2, ) = c21 = 5, g(3, ) = c31 = 6, and g(4, ) = c41 = 8. We obtaing(2,{3}) = c23 + g(3, ) = 15 g(2,{4}) = 18g(3,{2}) = 18 g(3,{4}) = 20g(4,{2}) = 13 g(4,{3}) = 15

g(2,{3,4}) = min{c23+g(3,{4}),c24+g(4,{3})} = 25g(3,{2,4}) = min{c32+g(2,{4}),c34+g(4,{2})} = 25g(4,{2,3}) = min{c42+g(2,{3}),c43+g(3,{2})} = 23

g(1,{2,3,4}) = min{c12+g(2,{3,4}),c13+g(3,{2,4}),c14+g(4,{2,3})}= min(35,40,43}= 35

• 5.9 The traveling salesperson problemLet N be the number of g(i,s), that have to be computed before g(1,V-{1}) i, computed for each value of |s| n-1 choices of iThe number of distinct sets of S of size k not including 1 and i

Recommended Documents