cse101_11_30_11

cse101_11_30_11 - longest common substring = 5 has to be...

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

View Full Document Right Arrow Icon
2 nd to final lecture 1. Longest common subsequence a. A, C, T, G, G, C, T, A, G G, I, G, A, C, A, G, T, T LCS has length 5. b. Given X[1…n] Y[1…m] What is the length of their LCS? c. SUBPROBLEM: T(I, j) = LCS of x[1…i], y[1…j] We want T(n, m) d. RECURSIVE FORMULATION T(I, j) = {1 + T(i-1, j-1) if x[i] = y[j] Max (T(i-1, j), T(I, j-1)) if not 0 1 2 3 4 5 6 . . n 0 0 0 0 0 0 0 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 N 0 e. Order in which to solve Row by row (top to bottom) Left-to-right within a row Or: column-by-column f. Code For I = 0 to n : T[I, 0] = 0 For j = 0 to m: T[0, j] = 0 For I = 1 to n: For j = 1 to m: If x[i] = y[j]: T[I, j] = 1 + T[I – 1, jj-1] Else T[I, j] = max(T[i-1, j], T[I, j-1]) Return T[n, m] 2. Longest common substring a. x = AGCTGACCTGA y = GCATCACTGAC
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: longest common substring = 5 has to be consecutive. b. Given (same as previous problem) c. Subproblem T(I, j) = longest common susbstring of x[1. .i], y[1j] That and exactly in x[i] and y[j] We want max of I,j T(I,j) d. Recursive formulation T(I, j) = 1 + T(i-1, j-1) if x[i] = y[j] Else, 0 e. The code is the same as before, except else T[I, j] = 0, return max number in T 3. Optimal binary search trees a. Dictionary data structure Begin 5% Do 40% Else 8% End 4% If 10% Then 10% While 23% Use a BST structure End Do then Begin else if while Expected # comparisons = 1 90.04) + 2(0.4 + 0.1) + 3(0.05 + 0.08 + 0.1 + 0.23) Do Begin while If Else then End Avg = 2.18 b....
View Full Document

Page1 / 2

cse101_11_30_11 - longest common substring = 5 has to be...

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