0 views

Uploaded by Enmusk

373

- Alpha Test Individual
- Joe L. Mott, Abraham Kandel, Theodore P. Baker Discrete Mathematics for Comp
- Julia Type Hierarchy
- Poisson Process Generation
- bfnbfnhhn
- Wiener
- Construction of Low-Density Parity-Check Codes Based on Frequency-Hopping Sequences
- dskj
- Problem E - Ouroboros Snake
- Fast Detour
- 101hw7w17
- Chap16 Solutions
- Multiple GROUP declarations in ALF
- 8 Permutation & Combination Part 1 of 4
- An Algorithm to Calculate the Day of the Week
- Solution for Example 2.5
- Box 004
- Sum of Square of Integers
- SurdsExamQuestions.pdf
- jrxml_params

You are on page 1of 14

Dynamic Programming

CSE373: Design

and Analysis of

Longest Common Subsequence

(LCS)

•

Given two sequences

X = x1, x2, …, xm

Y = y1, y2, …, yn

find a maximum length common subsequence (LCS)

of X and Y

•

Application: comparison of two DNA strings

Example

X = A, B, C, B, D, A, B X = A, B, C, B, D, A, B

Y = B, D, C, A, B, A Y = B, D, C, A, B, A

•

Both B, C, B, A and B, D, A, B are longest

common subsequences of X and Y (length = 4)

•

B, C, A, however is not a LCS of X and Y

Brute-Force Solution

•

For every subsequence of X, check whether it’s a

subsequence of Y

•

There are 2m subsequences of X to check

•

Each subsequence takes (n) time to check

• scan Y for first letter, from there scan for second, and so

on

•

Running time: (n2m)

LCS Recursive Solution

•

First we’ll find the length of LCS. Later we’ll modify

the algorithm to find LCS itself.

•

Define Xi, Yj to be the prefixes of X and Y of length i

and j respectively

•

Define c[i,j] to be the length of LCS of Xi and Yj

•

Then the length of LCS of X and Y will be c[m,n]

LCS Recursive Solution

•

We start with i = j = 0 (empty substrings of x and y)

•

Since X0 and Y0 are empty strings, their LCS is

always empty (i.e. c[0,0] = 0)

•

LCS of empty string and any other string is empty, so

for every i and j: c[0, j] = c[i,0] = 0

LCS Recursive Solution

•

When we calculate c[i,j], we consider two cases:

•

First case: x[i]=y[j]:

• one more symbol in strings X and Y matches, so the

length of LCS Xi and Yj equals to the length of LCS of

smaller strings Xi-1 and Yi-1 , plus 1

c[i 1, j 1] 1 if x[i ] y[ j ],

c[i, j ]

LCS Recursive Solution

•

Second case: x[i] != y[j]

• As symbols don’t match, our solution is not improved, and

the length of LCS(Xi , Yj) is the same as before (i.e.

maximum of LCS(Xi, Yj-1) and LCS(Xi-1,Yj)

c[i 1, j 1] 1 if x[i ] y[ j ],

c[i, j ]

max( c[i, j 1], c[i 1, j ]) otherwise

Computing the Length of the LCS

0 if i = 0 or j = 0

c[i, j] = c[i-1, j-1] + 1 if xi = yj

max(c[i, j-1], c[i-1, j]) if xi yj

0 1 2 n

yj: y1 y2 yn

0 xi 0 0 0 0 0 0

1 x1 0 first

2 x2 0 second

i

0

0

m xm 0

j

Additional Information

0 if i,j = 0

c[i, j] = c[i-1, j-1] + 1 if xi = yj

max(c[i, j-1], c[i-1, j]) if xi yj

b & c: yj: A C D F •

For a subproblem [i, j] it tells us

what choice was made to obtain

0 xi 0 0 0 0 0 0 the optimal value

1 A 0 •

If xi = yj

2 B b[i, j] = “ ”

0 c[i-1,j] •

Else, if c[i - 1, j] ≥ c[i, j-1]

i

3 C 0 c[i,j-1] b[i, j] = “ ”

else

0

b[i, j] = “ ”

m D 0

j

LCS-LENGTH(X, Y, m, n)

1. for i ← 1 to m

2. do c[i, 0] ← 0 The length of the LCS if one of the sequences

is empty is zero

3. for j ← 0 to n

4. do c[0, j] ← 0

5. for i ← 1 to m

6. do for j ← 1 to n Case 1: xi = yj

7. do if xi = yj

8. then c[i, j] ← c[i - 1, j - 1] + 1

9. b[i, j ] ← “ ” Case 2: xi yj

11. then c[i, j] ← c[i - 1, j]

12. b[i, j] ← “↑” Running time: (mn)

13. else c[i, j] ← c[i, j - 1]

Example

X = A, B, C, B, D, A

0 if i = 0 or j = 0

Y = B, D, C, A, B, A c[i, j] = c[i-1, j-1] + 1 if xi = yj

max(c[i, j-1], c[i-1, j]) if xi yj

0 1 2 3 4 5 6

If xi = yj yj B D C A B A

b[i, j] = “ ” 0 xi 0 0 0 0 0 0 0

Else if c[i - 11, j]A≥ 0

0

0

0 1 1 1

c[i, j-1] 2 B 0 1 1 1

1 2 2

b[i, j] = “ ” 3 C

0 1 1 2 2 2 2

else 4 B

0 1 1 2 2 3 3

b[i, j] = “ ”

5 D 0 1 2 2 2 3 3

6 A 0 1 2 2 3 3 4

7 B 0 1 2 2 3 4 4

4. Constructing a LCS

•

Start at b[m, n] and follow the arrows

•

When we encounter a “ “ in b[i, j] xi = yj is an element of

the LCS

0 1 2 3 4 5 6

yj B D C A B A

0 xi 0 0 0 0 0 0 0

1 A

0 0 0 0 1 1 1

2 B

0 1 1 1 1 2 2

3 C

0 1 1 2 2 2 2

4 B 0 1 1 2 2 3 3

5 D 0 1 2 2 2 3 3

6 A 0 1 2 2 3 3 4

7 B 0 1 2 2 3 4 4

PRINT-LCS(b, X, i, j)

1. if i = 0 or j = 0

Running time: (m + n)

2. then return

3. if b[i, j] = “ ”

4. then PRINT-LCS(b, X, i - 1, j - 1)

5. print xi

6. elseif b[i, j] = “↑”

7. then PRINT-LCS(b, X, i - 1, j)

8. else PRINT-LCS(b, X, i, j - 1)

- Alpha Test IndividualUploaded byxSubrilla
- Joe L. Mott, Abraham Kandel, Theodore P. Baker Discrete Mathematics for CompUploaded byShivam Gupta
- Julia Type HierarchyUploaded byJohnny Nelson
- Poisson Process GenerationUploaded byMadhu Babu Sikha
- bfnbfnhhnUploaded byPriyanka Priya
- WienerUploaded byDecker James
- Construction of Low-Density Parity-Check Codes Based on Frequency-Hopping SequencesUploaded byJung Hyun Kim
- dskjUploaded byAnon
- Problem E - Ouroboros SnakeUploaded byManea Silviu
- Fast DetourUploaded bymadan321
- 101hw7w17Uploaded bychrislake12
- Chap16 SolutionsUploaded byForm 4B
- Multiple GROUP declarations in ALFUploaded byJohn Michael Williams
- 8 Permutation & Combination Part 1 of 4Uploaded byabuabhilash
- An Algorithm to Calculate the Day of the WeekUploaded byPraveen Mathai
- Solution for Example 2.5Uploaded byNasrul Torres
- Box 004Uploaded byBrian Beckman
- Sum of Square of IntegersUploaded byAnhTam
- SurdsExamQuestions.pdfUploaded byNorzaifee Nizamudin
- jrxml_paramsUploaded byskadam00
- math 2.2Uploaded bysheena6
- Math 1Uploaded byErika Hanne Yap
- MathematicsUploaded bygprakash99
- WARM UP 1Uploaded bykhey
- math lbs 400Uploaded byapi-310514578
- Partial ProductsUploaded byArindam
- Latihan SetUploaded byazlina_4410
- Linear ProgrammingUploaded byNorsu'aidah Bt Amir
- Program Utk Latihan v2Uploaded byRifqi Syams
- Assignment 1Uploaded byjaswanth1017

- List_of_vitamins.docUploaded byEnmusk
- Last ClassUploaded byEnmusk
- L16 Graph Part05Uploaded byEnmusk
- L14 Graph Part03Uploaded byEnmusk
- Lec 19 Diabetes, Lipid ProfileUploaded byEnmusk
- Lec 1,2 Intro to Biology and LifeUploaded byEnmusk
- L15 Graph Part04Uploaded byEnmusk
- L13 Graph Part02Uploaded byEnmusk
- L12 Graph Part01Uploaded byEnmusk
- L11 DynamicProgramming_Part05Uploaded byEnmusk
- L10 DynamicProgramming_Part04Uploaded byEnmusk
- L08 DynamicProgramming_Part02Uploaded byEnmusk
- L01 AlgoAnalysisUploaded byEnmusk
- L07 DynamicProgramming_Part01Uploaded byEnmusk
- L04 DivideConquer_Part03Uploaded byEnmusk
- L03 DivideConquer_Part02Uploaded byEnmusk
- L06 Greedy Part02Uploaded byEnmusk
- L05 Greedy Part01Uploaded byEnmusk
- L02 DivideConquer_Part01Uploaded byEnmusk
- 373 Assignment 1Uploaded byEnmusk
- Assignment 5CapacitorUploaded byEnmusk
- Lec 16 DigestionUploaded byEnmusk
- Lec 1,2,3 RMUploaded byEnmusk
- Lec 17 Circulatory SystemUploaded byEnmusk
- Lec 15 HomeostasisUploaded byEnmusk
- Lec 18 Respiratory, Excretory SystemUploaded byEnmusk
- Lec 3 Classification of Living ThingsUploaded byEnmusk
- Lec 4,5 Chemistry of LifeUploaded byEnmusk
- Lec 1,2,3 RM.pdfUploaded byEnmusk

- kWiet Genset BrochureUploaded byanon-90168
- TU606 Maruti Suzuki 080724Uploaded bychand1234567893
- Controladora HP 830Uploaded byFlores Cortés Eduardo
- Rajesh RajUploaded byJorige Kotanagaramanjaneyulu
- Scaling on RO and AntiscalantsUploaded byblumunchie
- Introduction to counting processesUploaded byMarlon Santos
- How Do Columns in RC Buildings Resist EarthquakeUploaded bykooadu
- Africa Environment Outlook 3 - Authors guideUploaded byUnited Nations Environment Programme
- 1d Vacuum Toilet Sys Evac 125Uploaded bySham
- Pregnancy__Breastfeeding_Anti-infective_Agents.pdfUploaded byFatehyEtman
- Barrett Odum-2000 (1)Uploaded byAlonso Gutiérrez
- Garmin Bell 407gx w Sys Sw 1237 03 Cockpit Reference Guide 720924Uploaded bybibi
- Code-MATH-Course-Details.pdfUploaded byAnees Rahman
- Multilevel Voltage-Source-Converter Topologies for Industrial Medium-Voltage DrivesUploaded byVamsi Sakhamuri
- Business MathUploaded byJanrey Oriña Navalta
- Plasmonics:From Basics to Advanced TopicsUploaded byOzan Erturk
- T&C contrlUploaded bySTAB
- Time-Light - Hubbard_ BryanUploaded byYisney
- B2 M03 2012.09.19 Electrical FundamentalsUploaded byPilot Tech 918
- Little Notes on stochastic processesUploaded byJan Hula
- New Holland - B90B LOADER BACKHOE PARTS MANUAL.pdfUploaded bydimaqdc
- Intro to RealismUploaded bysamuel yeboah
- Green ChemistryUploaded byjaysolanki
- KR213_R600_DB_EN(1)Uploaded byRoberto Gustavo Manitio Arteaga
- jurnal pendukung konasUploaded byrosa
- FMVSS Part 581 - Bumper Test SystemUploaded byavi5050
- EIL Material Selection ChartUploaded byVijaya Sekhar
- Ardas Full DetailUploaded byAnmol Singh
- POTASSIUM AND CALCIUM ION CONCENTRATION INFLUENCE THE ETHANOL TOLERANCE OF YEAST ISOLATESUploaded byAnonymous CwJeBCAXp
- Omaree Autopsy ReportUploaded byKOB4