This data structure multiple choice (MCQ) question and answer set focuses on the "longest palindromic subsequence".

1. Which of the following methods can be used to solve the longest palindromic subsequence problem?

a) Dynamic programming

b) Recursion

c) brute force

d) Dynamic Programming, Recursion, Brute Force

see answer

answer : d

Explanation: Dynamic programming, recursion, and brute force can be used to solve the longest palindromic subsequence problem.

2. Which of the following is not a palindromic subsequence of the string “ababcdabba”?

a) abcba

b) aba

effort

d) down

see answer

answer : d

Explanation: 'adba' is not a palindromic sequence.

3. For which of the following is the length of the chord not equal to the length of the longest palindromic subsequence?

a) A string that is a palindrome

b) A rope of length one

c) A string that has all the same letters (e.g. aaaaaa)

d) Some strings of length two

see answer

answer : d

Explanation: A string of length 2, for example: ab is not a palindrome.

announcement

announcement

4. What is the length of the longest palindromic subsequence of the string “ababcdabba”?

a) 6

second) 7

c) 8

re) 9

see answer

answer: b

Explanation: The longest palindromic subsequence is “abbabba” and its length is 7.

5. What is the time complexity of the brute force algorithm used to find the length of the longest palindromic subsequence?

(a) O(1)

b) O(2^{norte})

swindler)

wear^{2})

see answer

answer: b

Explanation: In the brute force algorithm, all subsequences are found and the length of the longest palindromic subsequence is calculated. This takes exponential time.

Take Mock Data Structure Tests II - Chapter!

Start testing now:Chapter 1,2,3,4,5,6,7,8,9,10

6. For each non-empty string, the length of the longest palindromic substring is at least one.

A truth

b) False

see answer

answer: one

Explanation: A single character in any string can always be considered a palindrome and its length is one.

7. The longest palindromic subsequence is an example of ______________

a) greedy algorithm

b) 2D dynamic programming

c) 1D dynamic programming

d) divide and conquer

see answer

answer: b

Explanation: The longest palindromic subsequence is an example of 2D dynamic programming.

announcement

8. Consider the following code:

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);______________; E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "abbcdabba"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

Which of the following lines completes the above code?

a) strrev(str2)

b) str2 = str1

c) len2 = strlen(str2)

d) strlen(str2)

see answer

answer: one

Explanation: To find the longest palindromic subsequence, we need to reverse copy the string, which strrev does.

announcement

9. What is the time complexity of the following dynamic programming implementation for finding the longest palindromic subsequence where the string length is n?

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);effort(str2); E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "abbcdabba"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

a) O(n)

b) O(1)

swindler^{2})

d) O(2)

see answer

answer: c

Explanation: The time complexity of the above dynamic programming implementation to find the longest palindromic subsequence is O(n^{2}).

10. What is the spatial complexity of the following implementation of dynamic programming for finding the longest palindromic subsequence where the string length is n?

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);effort(str2); E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "abbcdabba"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

a) O(n)

b) O(1)

swindler^{2})

d) O(2)

see answer

answer: c

Explanation: The spatial complexity of the above dynamic programming implementation for finding the longest palindromic subsequence is O(n^{2}).

11. What is the value stored in arr[3][3] when the following code is executed?

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);effort(str2); E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "abbcdabba"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

a) 2

second) 3

c) 4

re) 5

see answer

answer: one

Explanation: The value stored in arr[3][3] when the above code is executed is 2.

12. What is the result of the following code?

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);effort(str2); E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "a B C D"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

a) 0

second) 1

c) 2

re) 3

see answer

answer: b

Explanation: The program prints the length of the longest palindromic subsequence, which is 1.

13. What is the result of the following code?

#include<stdio.h>#include<cadena.h>E Tmax_num(E Ta, E Tb){ e(a>b) give backa; give backb;}E Tlps(Characters *str1){ E Teu,j,Len;Len= failing(str1); Charactersstr2[Len+ 1]; stressed(str2,str1);effort(str2); E TArr[Len+ 1][Len+ 1]; for(eu= 0;eu<=Len;eu++)Arr[eu][0] = 0; for(eu= 0;eu<=Len;eu++)Arr[0][eu] = 0; for(eu= 1;eu<=Len;eu++) { for(j= 1;j<=Len;j++) { e(str1[eu-1] ==str2[j- 1])Arr[eu][j] = 1 +Arr[eu- 1][j- 1]; the restArr[eu][j] =max_num(Arr[eu- 1][j],Arr[eu][j- 1]); } } give backArr[Len][Len];}E Tdirector(){ Charactersstr1[] = "abdgkagdjbccbba"; E Tresponder=lps(str1); print("%d",responder); give back 0;}

a) 5

second) 7

c) 9

d) 11

see answer

answer: c

Explanation: The program prints the length of the longest palindromic subsequence, which is 9.

**Sanfoundry Global Education & Learning Series: Data Structures and Algorithms.**

To practice all areas of data structures and algorithms,__here is a complete set of 1000+ multiple choice questions and answers__.

«Previous - Data Structure Q&A: Longest Common Subsequence

»Next - Data Structure Q&A - Edit Distance Issue

**Next steps:**

- Freedom-youCertificate of Merit in Data Structure II
- To participate inData Structure Certification Contest II
- become aBest Ranked in Data Structure II
- To loadData structure tests II
- Practical tests by chapters:Chapter 1,2,3,4,5,6,7,8,9,10
- Simulated tests by chapters:Chapter 1,2,3,4,5,6,7,8,9,10

**Related posts:**

- PracticeMCQ data structure
- comprarAlgorithm design and analysis books
- RequestInternship in Computer Science
- RequestInternship in Information Technology
- PracticeMCQ Programming