GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The longest palindromic subsequence of the string BCABDACBDCA has length:
- A. 7
- B. 6
- C. 8
- D. 9
Correct answer: A. 7
The DP L[i][j] = L[i+1][j−1] + 2 if s[i] = s[j], else max(L[i+1][j], L[i][j−1]) gives 7 (matching a brute force over all subsequences), for example B C A D A C B. The longest common substring and palindromic substring would be much shorter.
More Algorithms questions
- What is the minimum number of cuts needed to partition the string abacbbcabbacab into substrings that are all palindromes?
- How many DIFFERENT non-empty strings occur as subsequences of BANANAB (subsequences need not be contiguous; equal strings from different…
- Ten symbols with frequencies 2, 3, 4, 5, 6, 8, 10, 15, 20, 27 (total 100) are encoded with an optimal ternary (3-ary) Huffman code, whose…
- Eight files of sizes 4, 7, 9, 12, 15, 18, 22 and 25 are merged using 3-way merges (merging any 3 files costs the sum of their sizes; merge…
- Which of the following statements about Huffman coding on a set of symbols with positive frequencies is/are correct? I. If f(a) > f(b)…
- Intervals (start, end, weight) are (0,3,4), (1,5,6), (2,6,10), (5,8,7), (4,9,9), (7,10,3), (9,12,8), (8,13,5), (12,15,6), (10,16,12); two…