Question
#include<stdio.h>
#include<string.h>
int max_num(int a, int b)
{
if(a > b)
return a;
return b;
}
int lps(char *str1)
{
int i,j,len;
len = strlen(str1);
char str2[len + 1];
strcpy(str2, str1);
strrev(str2);
int arr[len + 1][len + 1];
for(i = 0; i <= len; i++)
arr[i][0] = 0;
for(i = 0; i <= len; i++)
arr[0][i] = 0;
for(i = 1; i <= len; i++)
{
for(j = 1; j <= len; j++)
{
if(str1[i-1] == str2[j - 1])
arr[i][j] = 1 + arr[i - 1][j - 1];
else
arr[i][j] = max_num(arr[i - 1][j], arr[i][j - 1]);
}
}
return arr[len][len];
}
int main()
{
char str1[] = "ababcdabba";
int ans = lps(str1);
printf("%d",ans);
return 0;
}
a.
2
b.
3
c.
4
d.
5
Posted under Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the value stored in arr[3][3] when the following code is executed?
Similar Questions
Discover Related MCQs
Q. Which of the following methods can be used to solve the edit distance problem?
View solution
Q. The edit distance satisfies the axioms of a metric when the costs are non-negative.
View solution
Q. Which of the following is an application of the edit distance problem?
View solution
Q. In which of the following cases will the edit distance between two strings be zero?
View solution
Q. Suppose each edit (insert, delete, replace) has a cost of one. Then, the maximum edit distance cost between the two strings is equal to the length of the larger string.
View solution
Q. Consider the strings “monday” and “tuesday”. What is the edit distance between the two strings?
View solution
Q. Consider the two strings “”(empty string) and “abcd”. What is the edit distance between the two strings?
View solution
Q. Wagner–Fischer is a ____________ algorithm.
View solution
Q. Wagner–Fischer algorithm is used to find ____________
View solution
Q. What is the edit distance between the strings “abcd” and “acbd” when the allowed operations are insertion, deletion and substitution?
View solution
Q. For which of the following pairs of strings is the edit distance maximum?
View solution
Q. What is the time complexity of the Wagner–Fischer algorithm where “m” and “n” are the lengths of the two strings?
View solution
Q. Which of the following is NOT a Catalan number?
View solution
Q. Which of the following numbers is the 6th Catalan number?
View solution
Q. Which of the following is/are applications of Catalan numbers?
View solution
Q. Which of the following methods can be used to find the nth Catalan number?
View solution
Q. Which of the following implementations of Catalan numbers has the smallest time complexity?
View solution
Q. Which of the following implementations of Catalan numbers has the largest space complexity(Don’t consider the stack space)?
View solution
Q. Which of the following methods can be used to solve the assembly line scheduling problem?
View solution
Q. What is the time complexity of the brute force algorithm used to solve the assembly line scheduling problem?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!