# Lecture20 - 1 CSE 421 Algorithms Richard Anderson Lecture...

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

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: 1 CSE 421 Algorithms Richard Anderson Lecture 20 Memory Efficient Longest Common Subsequence Longest Common Subsequence • C=c 1 …c g is a subsequence of A=a 1 …a m if C can be obtained by removing elements from A (but retaining order) • LCS(A, B): A maximum length sequence that is a subsequence of both A and B ocurranec occurrence attacggct tacgacca LCS Optimization • A = a 1 a 2 …a m • B = b 1 b 2 …b n • Opt[ j, k] is the length of LCS(a 1 a 2 …a j , b 1 b 2 …b k ) Optimization recurrence If a j = b k , Opt[ j,k ] = 1 + Opt[ j-1, k-1 ] If a j != b k , Opt[ j,k] = max(Opt[ j-1,k], Opt[ j,k-1]) Dynamic Programming Computation Storing the path information A[1..m], B[1..n] for i := 1 to m Opt[i, 0] := 0; for j := 1 to n Opt[0,j] := 0; Opt[0,0] := 0; for i := 1 to m for j := 1 to n if A[i] = B[j] { Opt[i,j] := 1 + Opt[i-1,j-1]; Best[i,j] := Diag; } else if Opt[i-1, j] >= Opt[i, j-1] { Opt[i, j] := Opt[i-1, j], Best[i,j] := Left; } else { Opt[i, j] := Opt[i, j-1], Best[i,j] := Down; } a 1 …a m b 1 …b n 2...
View Full Document

## This note was uploaded on 02/25/2012 for the course CSE 421 taught by Professor Richardanderson during the Fall '06 term at University of Washington.

### Page1 / 4

Lecture20 - 1 CSE 421 Algorithms Richard Anderson Lecture...

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

View Full Document
Ask a homework question - tutors are online