cse101_11_28_11

cse101_11_28_11 - e. How to reconstruct actual list of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic Programming 1. String reconstruction a. Corrupted document punctuation removed a.i. Anonymousarrayoflettersd Reconstruct original documents given access to a dictionary. b. Input Array of characters x[1…n] Dictionary funnnction: dict(w) = true if w is a valid word false if not c. Greedy fails d. Step 1: define subproblem For 1 <= j <= n, define T(j) = true if x[1…j] is a valid sequence of words False otherwise We want T(n) Step 2: express subproblem in terms of smaller subproblems T(j) = true if there is some k <= j such that T(k-1) is true and x[k…j] is a valid word T(0) = true. Step 3: in what order should subproblems be solved? T(1), T(2), T(3) Step 4: algorithm T[0] = true For j = 1 to n T[j] = false For k = 1 to j If dict([k…]j and T[k-1]: T[j] = true B[j] = k Return T[n]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: e. How to reconstruct actual list of words Keep backpointers For any j with T[j] = true, let B[j] = position at which last word begins Actually outputting the words S = empty stack J = n While j > 0 : Push(x[b[jk]], s) J = B[j] 1 While s != 0 Output pops 2. Longest common subsequence a. Ex. Two sequences A, C, T, G, C, T, A, G G, T, G, A, C, A, G, T, T Common subsequence GT, AGT Longest = GGCAG or TGCAG b. Given two sequences X[1n] And Y[1m] Find the length of their LCS. c. Step 1: subproblem For 1 <= i <= n, 1 <= j <= m, T(I, j) = length of LCS of x[1i] and y[1. .j] Step 2: express subproblem in terms of smaller subproblems T(I, j) = 1 + T(i-1, j-1) if x[i] = y[j] Max(T(i-1,j, T(I,j-1)) d....
View Full Document

This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.

Page1 / 2

cse101_11_28_11 - e. How to reconstruct actual list of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online