Algorithms - Dynamic Programming Let graph G = (V,E) be a path with n vertices v
ID: 3805320 • Letter: A
Question
Algorithms - Dynamic Programming
Let graph G = (V,E) be a path with n vertices v1,v2,....,vn, and n-1 edges (vi,vi+1), 1 <= i <= n-1. On each vertex vi there is a positive integer weight wi. A subset of vertices is independent if there is no edge between any pair of vertices in the subset. The weight of a subset is the sum of the weights on its vertices. Design an efficient dynamic programming algorithm to find a maximum weight independent set in G and analyze the complexity of your algorithm. Describe the subproblems that you use in your dynamic programming solution and show the underlying DAG.
Explanation / Answer
Answer:
Define diff (i, j) = 0 if x[i] = y[j] and diff (i, j) = 1 otherwise E(i, j) = min{1 + E(i 1, j), 1 + E(i, j 1), diff (i, j) + E(i 1, j 1)} function edit-distance(X, Y) for i = 0, 1, 2, ... m E(i, 0) = i; for j = 1, 2, ... n E(0, j) = j; for i = 1, 2, ... m for j = 1, 2, ... n E(i, j) = min { E(i - 1, j) + 1, E(i, j - 1) + 1, E(i - 1, j - 1) + diff(i, j) }; return E(m, n);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.