



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Optimization
Optimization problems have the form: Find a solution minimizing/maximizing some value.
Examples:
Multiply a sequence of matrices minimbizing the number of multiplications.
From two strings, find a common subsequence of maximum length.
Give change minimizing the number of coins.
Schedule a room to maximize the number of meetings.
Find a character code to minimize the length of a string.
Find a spanning tree with the minimum sum of weights.
Find a path between two vertices of minimum weight.
Find the smallest set of edges covering all ver- tices.
Dynamic Programming
Dynamic programming is a technique for solving some optimization problems.
A dynamic programming solution to a problem usually involves:
Notation: Use opt(.. .) to denote optimal value. Use arg(.. .) to denote optimal parameters.
Algorithm: P [0... n] are the dimensions.
Matrix-Chain-Order(P [0... n]) for i ← 1 to n do opt[i, i] ← 0 for j ← 2 to n do for i ← j − 1 downto 1 do opt[i, j] ← ∞ for k ← i to j − 1 do q ← opt[i, k] + opt[k + 1, j]
Construction: A[i] is the ith matrix.
Matrix-Chain-Multiply(A, i, j) if i = j then return A[i] else X ← M.-C.-M.(A, i, arg[i, j]) Y ← M.-C.-M.(A, arg[i, j] + 1, j) return Matrix-Multiply(X, Y )
Longest Common Subseqeunce
Longest common subsequence (LCS) of “kahijedcdelln” and “hzpidysvdquen” is “hidden”. An example application is diff.
Structure: Let X = 〈x 1 ,... , xm〉 and Y = 〈y 1 ,... , yn〉. Let Z = 〈z 1 ,... , zk〉 be an LCS of X and Y.
Recursive Definition: Let opt(m, n) be the LCS length of 〈x 1 ,... , xm〉 and 〈y 1 ,... , yn〉
if m = 0 or n = 0, then opt(m, n) = 0 else if xm = yn, then
opt(m, n) = 1 + opt(m − 1 , n − 1)
else
opt(m, n) = max(opt(m − 1 , n), opt(m, n − 1)