Which of the following lines completes the above code?
strrev(str2)
str2 = str1
len2 = strlen(str2)
strlen(str2)
Answer and explanation
To find the longest palindromic subsequence, we need to reverse the copy of the string, which is done by strrev.
ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
8 practice sets · Page 1 of 1
Which of the following lines completes the above code?
strrev(str2)
str2 = str1
len2 = strlen(str2)
strlen(str2)
To find the longest palindromic subsequence, we need to reverse the copy of the string, which is done by strrev.
Longest palindromic subsequence is an example of ______________
Greedy algorithm
2D dynamic programming
1D dynamic programming
Divide and conquer
Longest palindromic subsequence is an example of 2D dynamic programming.
For every non-empty string, the length of the longest palindromic subsequence is at least one.
True
False
A single character of any string can always be considered as a palindrome and its length is one.
What is the time complexity of the brute force algorithm used to find the length of the longest palindromic subsequence?
O(1)
O(2^{n})
O(n)
O(n^{2})
In the brute force algorithm, all the subsequences are found and the length of the longest palindromic subsequence is calculated. This takes exponential time.
What is the length of the longest palindromic subsequence for the string "ababcdabba"?
6
7
8
9
The longest palindromic subsequence is "abbabba" and its length is 7.
For which of the following, the length of the string is not equal to the length of the longest palindromic subsequence?
A string that is a palindrome
A string of length one
A string that has all the same letters(e.g. aaaaaa)
Some strings of length two
A string of length 2 for eg: ab is not a palindrome.
Which of the following is not a palindromic subsequence of the string "ababcdabba"?
abcba
abba
abbbba
adba
'adba' is not a palindromic sequence.
Which of the following methods can be used to solve the longest palindromic subsequence problem?
Dynamic programming
Recursion
Brute force
Dynamic programming, Recursion, Brute force
Dynamic programming, Recursion, Brute force can be used to solve the longest palindromic subsequence problem.