Docsity

Dynamic Programming Algorithms: Dynamic Solution Tables, Study notes of Computer Science

Toggle sidebar
bg1
CS1510, Design and Analysis of Algorithms, Fall 2006
Patchrawat Uthaisombut
Dynamic Programming
general coin change problem
Le
t
CHvL
b
e the minimu
m
numbe
r
of coins of denominations 4, 3, 1 needed to make change for vdollars
CHvL=min 8CHv-4L+1, CHv-3L+1, CHv-1L+1<
knapsack problem
Let PHi,wLbe the maximum profit that obtainable, with weight at most w, from items in the set 81, 2, …, i<
PHi,wL=max 8PHi-1, wL,PHi-1, w-wiL+pi<
chained matrix multiplication
Let MHi,jLbe the minimum number of multiplications needed to compute AiAi+1
…Aj
MHi,jL=mini§k§j-18MHi,kL+MHk+1, jL+pi-1 pk pj<
optimal binary search tree
Let CHi,jLbe the cost of an optimal binary search tree containing real keys i,…, jand dummy keys i-1, …, j
CHi,jL=mini§r§j8CHi,r-1L+cHr+1, jL+wHi,jL<
longest common subsequence
Let LHi,jLbe the length of a longest common subsequence of x1
x2
…xiand y1
y2
…yj
L Hi,jL=9LHi-1, j-1L+1ifxi=yj
max 8LHi,j-1L,LHi-1, jL< if xi∫yj
sequence alignment
Let CHi,jLbe the cost of an optimal alignment of x1
x2
…xiand y1
y2
…yj
C Hi,jL=max 9
LHi-1, j-1L+a
xi yj
LHi,j-1L+d
LHi-1, jL+d
=
Floyd's shortest path algorithm
Let LHi,j,kLbe the length of a shortest path from ito jwhere the internal nodes are from the set 81, 2, …, k<
We want LHi,j,nLfor all i,j
LHi,j,kL=mi
n
8LHi,j,k-1L,LHi,k,k-1L+LHk,j,k-1L<
bitonic euclidean TSP
Label the vertices using positive integer from left to right
For i<j, let LHi,jLbe the length of a shortest bitonic spanning path for vertices in the set 81, 2, …, i<
where one path ends at vertex iand the other path ends at vertex j
We want min1§j§i-18LHn,jL+dj,n<
LHi,jL=min 8LHi-1, jL+di-1
,
i, min1§k§i-2LHi-1, kL+dk
,
i<
maximum contiguous sublist
DP-summary.nb 1
pf2

Partial preview of the text

Download Dynamic Programming Algorithms: Dynamic Solution Tables and more Study notes Computer Science in PDF only on Docsity!

CS1510, Design and Analysis of Algorithms, Fall 2006 Patchrawat Uthaisombut Dynamic Programming

general coin change problem Let CHvL be the minimum number of coins of denominations 4, 3, 1 needed to make change for v dollars CHvL = min 8 CHv - 4 L + 1, CHv - 3 L + 1, CHv - 1 L + 1 <

knapsack problem Let PHi, wL be the maximum profit that obtainable, with weight at most w, from items in the set 8 1, 2, …, i < PHi, wL = max 8 PHi - 1, wL, PHi - 1, w - wiL + pi<

chained matrix multiplication Let M Hi, jL be the minimum number of multiplications needed to compute Ai Ai+ 1 … A (^) j M Hi, jL = mini§k§ j- 1 8 M Hi, kL + M Hk + 1, jL + pi- 1 pk p (^) j <

optimal binary search tree Let CHi, jL be the cost of an optimal binary search tree containing real keys i, …, j and dummy keys i - 1, …, j CHi, jL = mini§r§ j 8 CHi, r - 1 L + cHr + 1, jL + wHi, jL <

longest common subsequence Let LHi, jL be the length of a longest common subsequence of x 1 x 2 … xi and y 1 y 2 … y (^) j

L Hi, jL = 9

LHi - 1, j - 1 L + 1 if xi = y (^) j max 8 LHi, j - 1 L, LHi - 1, jL < if xi ∫ y (^) j

sequence alignment Let CHi, jL be the cost of an optimal alignment of x 1 x 2 … xi and y 1 y 2 … y (^) j

C Hi, jL = max 9

LHi - 1, j - 1 L + ax (^) i y (^) j LHi, j - 1 L + d LHi - 1, jL + d

Floyd's shortest path algorithm Let LHi, j, kL be the length of a shortest path from i to j where the internal nodes are from the set 8 1, 2, …, k< We want LHi, j, nL for all i, j LHi, j, kL = min 8 LHi, j, k - 1 L, LHi, k, k - 1 L + LHk, j, k - 1 L <

bitonic euclidean TSP Label the vertices using positive integer from left to right For i < j, let LHi, jL be the length of a shortest bitonic spanning path for vertices in the set 8 1, 2, …, i< where one path ends at vertex i and the other path ends at vertex j We want min 1 § j§i- 1 8 LHn, jL + d (^) j,n< LHi, jL = min 8 LHi - 1, jL + di-1,i, min 1 § k§i- 2 LHi - 1, kL + dk,i <

maximum contiguous sublist

DP-summary.nb 1

Let V HiL be the value of a maximum contiguous sublist of s 1 , s 2 , …, si ending with s (^) i We want max 1 §i§n V HiL V HiL = max 8 V Hi - 1 L + s (^) i, si<

Longest Increasing Subsequence (LIS) Let LHiL be the length of a longest increasing subsequence of x 1 , x 2 , …, xi ending with xi We want max 1 §i§n LHiL LHiL = maxj 8 LH jL + 1 < where the maximum is over all j such that 0 § j < i and x (^) j < xi

making change with limited number of coins Let CHi, vL be the size of a smallest multiset that is a subset of 8 d 1 , d 2 , …, di< to make change for v dollars Let CHi, vL be ¶ if there is no such set CHi, vL = min 8 CHi - 1, vL, CHi - 1, v - diL + 1 <

price-collecting path Let SHi, jL be the largest weight of any shortest path from node H0, 0L to node Hi, jL in grid graph G SHi, jL = max 8 SHi, j - 1 L, SHi - 1, jL < + wi, j

rocket assembly Let CHi, kL be the cost of an optimal assembly sequence to assemble pieces i, …, k CHi, kL = mini§ j§k- 1 HCHi, jL + CH j + 1, kL + f Hi, j, kLL

word segmentation Let CHiL be the quality of an optimal segmentation for the string containing letters s 1 s 2 …si CHiL = max 0 § j§i- 1 CH jL + qualityHs (^) j+ 1 s (^) j+ 2 …siL

printing neatly Let CHiL be the penalty of an optimal layout for words i, …, n We want to compute CH 1 L CHiL = minj 9 CH j + 1 L + IL - ⁄kj=^ iwk M 2 = where the minimum is taken over all j such that i § j § n - 1 and ⁄kj=^ iwk § L Initial condition CHiL = 0 if ⁄k^ n=^ iwk § L

DP-summary.nb 2