Question

LCS (Longest Common Subsequence) problem consists in finding the longest subsequence of characters that is present...

 

LCS (Longest Common Subsequence) problem consists in finding the longest subsequence of characters that is present in two given sequences in the same order.

A subsequence is a sequence of characters that don't have to be consecutive.

For example, for the following inputs, the length of the LCS is 4

X: ABCBDAB

Y: BDCABA

And one of the LCS is BDAB

The following code is a solution for such problem, which values must be stored in the variable key for it to properly work?

Inputs: X and Y are strings to be analysed. n is the number of characters in X. m is the number of characters in Y. table is a dictionary with the solutions to the subproblems.

Output: The maximum number of characters in a LCS of X and Y

function LCS(X, n, Y, m, table)

    if n < 0 or m < 0

        return 0

    if key not in table

        if X[n] == Y[m]

            table[key] = LCS(X, n-1, Y, m-1, table) + 1

        else

            in_x = LCS(X, n-1, Y, m, table)

            in_y = LCS(X, n, Y, m-1, table)

            table[key] = max(in_x, in_y)

    

    return table[key]

a) X and Y

b) n

c) m

d) m and n

e) The base cases

Which is the correct answer?

Homework Answers

Answer #1

Option (d) is the correct answer.

The values of m and n (length of both strings) must be stored in the variable key for the proper working of the code. At first, we must check if the end for either sequence has reached. If not, then we must check if the last character of the strings matches. We also need to check the condition if they don't match.

Option (a) is incorrect as we need to store the string lengths, not the strings.

Option (b) is incorrect as both m and n must be stored.

Option (c) is incorrect as both m and n must be stored.

Option (e) is incorrect as the base case will be the not null check.

Please comment in case of any doubt.
Please upvote if this helps.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Complete a function definition in C for strmatch. For this problem, you can't use any <string.h>...
Complete a function definition in C for strmatch. For this problem, you can't use any <string.h> library functions. In c, two strings match exactly if they have the same characters in the same order and same length. Consider this: int strmatch(const char *x, const char *b); //Needs each of x and y points to the beginning of a string. //Promises to return value 1 if the two strings match exactly. If they don't match, the return value is 0. For...
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...
Problem 1: Relations among Useful Discrete Probability Distributions. A Bernoulli experiment consists of only one trial...
Problem 1: Relations among Useful Discrete Probability Distributions. A Bernoulli experiment consists of only one trial with two outcomes (success/failure) with probability of success p. The Bernoulli distribution is P (X = k) = pkq1-k, k=0,1 The sum of n independent Bernoulli trials forms a binomial experiment with parameters n and p. The binomial probability distribution provides a simple, easy-to-compute approximation with reasonable accuracy to hypergeometric distribution with parameters N, M and n when n/N is less than or equal...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3,...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 n = 12 b) Calculate 1) the average or average 2) quartile-1 3) quartile-2 or medium 4) quartile-3 5) Draw box diagram (Box & Wisker) II. PROBABILITY 1. Answer the questions using the following contingency table, which collects the results of a study to 400 customers of a store where you want to analyze the payment method. _______B__________BC_____ A...
In this problem you will use the cursor tracker code from the previous homework assignment to...
In this problem you will use the cursor tracker code from the previous homework assignment to measure frequency responses to various sinusoidal inputs and then generate a Bode plot. Use the Matlab file track cursor.m provided on Blackboard for a proportional controller with K = 0.1. After the tracker equilibrates, generate a sinusoidal input by moving the cursor back and forth and determine the gain and phase. The gain is the ratio of the amplitude of the output sinusoid over...
R Code Directions: All work has to be your own, you may not work in groups....
R Code Directions: All work has to be your own, you may not work in groups. Show all work. Submit your solutions in a pdf document on Moodle. Include your R code (which must be commented and properly indented) in the pdf file. Name this pdf file ‘your last name’-HW5.pdf. Also submit one text file with your R code, which must be commented and properly indented. You may only use ‘runif’ to generate random numbers; other random number generating functions...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...