4. Consider two sequences X = ABCBDA and Y = CABBDA. Find LCS (Longest Common Subsequence) performing: 4.a Compute c[] and b[] (like we did in Lec9.1), draw the table. 4.b Print LCS with PrintLCSO method, describe the steps. 4.c Convert PrintLCSO from recursive into an iterative algorithm. Write your Pseudocode with commentaries. 4.d Modify the code (LCSLength() and PrintLCSO) adding a parameter I (length of a subsequence) s.t. it prints the first common subsequence of length / or prints "No common subsequence of length I" if there is no common subsequence of length 1.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

4. Consider two sequences X = ABCBDA and Y = CABBDA. Find LCS (Longest Common Subsequence) performing:

4.a Compute c[] and b[] (like we did in Lec9.1), draw the table.

4.b Print LCS with PrintLCSO method, describe the steps.

4.c Convert PrintLCSO from recursive into an iterative algorithm. Write your Pseudocode with commentaries.

4.d Modify the code (LCSLength() and PrintLCSO) adding a parameter I (length of a subsequence) s.t. it prints the first common subsequence of length / or prints "No common subsequence of length I" if there is no common subsequence of length 1. 

Computing the Length
LCSLength(X, Y, m, n)
let b[1..m, 1..n] and c[0..m, 0..n] be new tables (2d arrays)
for i = 1 tom
c[i, 0] = 0 // first column
jo 1 2 3 4 5 6
for j = 0 to n
y, BDCABA
x 0 0 0 00 0 0
i
В
c[0, j] = 0 // first row
for i = 1 tom
for j = 1 to n
if x, == y;
c[i, j] = c[i - 1, j - 1] + 1
bli, j] = "R"
else if c[i - 1, j] > c[i, j - 1]
c[i, j] = c[i - 1, j]
b[i, j] = “ ↑ "
1 0 1 0
10 k 1
+1 K 1
2
в о
+ 1
+ 1
↑ 1 R 2 + 2
↑ 1
↑ 1 k 2 +2 1 2 1 2
4
B 01 ↑ 1
↑ 2
1 2 K 3
+ 3
%3D
D
↑ 1 R 2
1 2 1 2 1 3 ↑ 3
А
↑ 1
↑ 2
1 2 K 3
↑ 3
else c[i, j] = c[i, j - 1]
b[i, j] = “+"
7
В
↑ 2
↑ 3
return c and b
4.
4.
A
Transcribed Image Text:Computing the Length LCSLength(X, Y, m, n) let b[1..m, 1..n] and c[0..m, 0..n] be new tables (2d arrays) for i = 1 tom c[i, 0] = 0 // first column jo 1 2 3 4 5 6 for j = 0 to n y, BDCABA x 0 0 0 00 0 0 i В c[0, j] = 0 // first row for i = 1 tom for j = 1 to n if x, == y; c[i, j] = c[i - 1, j - 1] + 1 bli, j] = "R" else if c[i - 1, j] > c[i, j - 1] c[i, j] = c[i - 1, j] b[i, j] = “ ↑ " 1 0 1 0 10 k 1 +1 K 1 2 в о + 1 + 1 ↑ 1 R 2 + 2 ↑ 1 ↑ 1 k 2 +2 1 2 1 2 4 B 01 ↑ 1 ↑ 2 1 2 K 3 + 3 %3D D ↑ 1 R 2 1 2 1 2 1 3 ↑ 3 А ↑ 1 ↑ 2 1 2 K 3 ↑ 3 else c[i, j] = c[i, j - 1] b[i, j] = “+" 7 В ↑ 2 ↑ 3 return c and b 4. 4. A
Printing the LCS
PrintLCS(b,X, i, j)
if i == 0 or j ==0
return None
if b[i, j] == "R"
PrintLCS(b, X, i - 1, j - 1)
jo 1
2
3 4 5 6
x BD CABA
3 A
i
В
В
print x,
X 0 0 0
0 0 0 0
else if b[i, j] == "↑"
PrintLCS(b, X, i - 1, j)
1
A 0 10
10 k 1
+1R 1
2
B 0
+ 1
+ 1
↑ 1 k 2 + 2
else PrintLCS(b, X, i, j - 1)
co 11
↑ 1 k 2
↑ 2
+ 2 1 2
Initial call: PrintLCS(b, X, m, n)
4 B0k 1
↑ 1 12 1 2 K 3 + 3
Running time: 0(m+n).
D0 11 2
A 0 11
7 B01
1 2 1 2
↑ 3 1 3
Overall running time for LCS is
↑ 2
↑ 2 R 3 1 3 R 4
Ө (mn) + Ө(m+n) —
O(mn)
↑ 2 1 2 1 3 R 4
↑ 4
Transcribed Image Text:Printing the LCS PrintLCS(b,X, i, j) if i == 0 or j ==0 return None if b[i, j] == "R" PrintLCS(b, X, i - 1, j - 1) jo 1 2 3 4 5 6 x BD CABA 3 A i В В print x, X 0 0 0 0 0 0 0 else if b[i, j] == "↑" PrintLCS(b, X, i - 1, j) 1 A 0 10 10 k 1 +1R 1 2 B 0 + 1 + 1 ↑ 1 k 2 + 2 else PrintLCS(b, X, i, j - 1) co 11 ↑ 1 k 2 ↑ 2 + 2 1 2 Initial call: PrintLCS(b, X, m, n) 4 B0k 1 ↑ 1 12 1 2 K 3 + 3 Running time: 0(m+n). D0 11 2 A 0 11 7 B01 1 2 1 2 ↑ 3 1 3 Overall running time for LCS is ↑ 2 ↑ 2 R 3 1 3 R 4 Ө (mn) + Ө(m+n) — O(mn) ↑ 2 1 2 1 3 R 4 ↑ 4
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education