Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description Given two sequences s 1 and s 2 ( of any type ) . Find their longest common subsequence ( s ) ( LCS

Description
Given two sequences s1 and s2(of any type). Find their longest common subsequence(s)(LCS). For example, let s1={3,6,5,7,7,1,4,8} and s2={4,45,7,7,1,9,3,6}. Their LCS is {7,7,1} of length 3. Implement this function as a template that works on any class T, and call your function template with int. The I/O format is as follows.
Input an integer indicating the length of the sequence.
Each element of a sequence is separated by a whitespace.
The user first inputs two sequences. Then s/he inputs a mode as follows.
If mode is len then your program should only output the length of the LCS.
If mode is seq then your program should output all LCSs. If there are more than one, then your program should output them in lexicographic order.
Sample Input1
14
3435343412345678910
13
923483251234568899340
len
Sample Output1
6
Sample Input2
14
3435343412345678910
13
923483251234568899340
str
Sample Output2
123456
Sample Input3
10
18314775396
11
8785392914710
str
Sample Output3
147
539

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

How important is it to gather primary data?

Answered: 1 week ago