{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cse101_11_28_11

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

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

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]

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

View Full Document
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[j…k]], 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[1…n] And Y[1…m] 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[1…i] 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

{[ snackBarMessage ]}

### Page1 / 2

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

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

View Full Document
Ask a homework question - tutors are online