Data Structure Multiple Choice Questions on “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
Answer: d
Clarification: Dynamic programming, Recursion, 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”? Answer: d 3. For which of the following, the length of the string is not equal to the length of the longest palindromic subsequence? 4. What is the length of the longest palindromic subsequence for the string “ababcdabba”? Answer: b 5. What is the time complexity of the brute force algorithm used to find the length of the longest palindromic subsequence? Answer: b 6. For every non-empty string, the length of the longest palindromic subsequence is at least one. Answer: a 7. Longest palindromic subsequence is an example of ______________ Answer: b 8. Consider the following code: Which of the following lines completes the above code? Answer: a 9. What is the time complexity of the following dynamic programming implementation to find the longest palindromic subsequence where the length of the string is n? a) O(n) Answer: c 10. What is the space complexity of the following dynamic programming implementation to find the longest palindromic subsequence where the length of the string is n? a) O(n) Answer: c 11. What is the value stored in arr[3][3] when the following code is executed? a) 2 Answer: a 12. What is the output of the following code? a) 0 Answer: b 13. What is the output of the following code? a) 5 Answer: c
a) abcba
b) abba
c) abbbba
d) adba
Clarification: ‘adba’ is not a palindromic sequence.
a) A string that is a palindrome
b) A string of length one
c) A string that has all the same letters(e.g. aaaaaa)
d) Some strings of length two
Answer: d
Clarification: A string of length 2 for eg: ab is not a palindrome.
a) 6
b) 7
c) 8
d) 9
Clarification: The longest palindromic subsequence is “abbabba” and its length is 7.
a) O(1)
b) O(2n)
c) O(n)
d) O(n2)
Clarification: In the brute force algorithm, all the subsequences are found and the length of the longest palindromic subsequence is calculated. This takes exponential time.
a) True
b) False
Clarification: A single character of any string can always be considered as a palindrome and its length is one.
a) Greedy algorithm
b) 2D dynamic programming
c) 1D dynamic programming
d) Divide and conquer
Clarification: Longest palindromic subsequence is an example of 2D dynamic programming.#include
a) strrev(str2)
b) str2 = str1
c) len2 = strlen(str2)
d) strlen(str2)
Clarification: To find the longest palindromic subsequence, we need to reverse the copy of the string, which is done by strrev.#include
b) O(1)
c) O(n2)
d) O(2)
Clarification: The time complexity of the above dynamic programming implementation to find the longest palindromic subsequence is O(n2).#include
b) O(1)
c) O(n2)
d) O(2)
Clarification: The space complexity of the above dynamic programming implementation to find the longest palindromic subsequence is O(n2).#include
b) 3
c) 4
d) 5
Clarification: The value stored in arr[3][3] when the above code is executed is 2.#include
b) 1
c) 2
d) 3
View Answer
Clarification: The program prints the length of the longest palindromic subsequence, which is 1.#include
b) 7
c) 9
d) 11
Clarification: The program prints the length of the longest palindromic subsequence, which is 9.