ProgrammingVery hardCAT · MBA placement
The minimum number of insertions or deletions needed to make the string "abcca" a palindrome is len(s) - LPS(s), where LPS is the length of the longest palindromic subsequence. The procedure below computes the answer. What is printed?
The minimum number of insertions or deletions needed to make the string "abcca" a palindrome is len(s) - LPS(s), where LPS is the length of the longest palindromic subsequence. The procedure below computes the answer. What is printed?
L[i][i] = 1; for longer ranges fill L with the standard recurrence LPS = L[0][n-1] Print n - LPS
- A. 5
- B. 4
- C. 2
- D. 1
Correct answer: D. 1
The longest palindromic subsequence of abcca is acca, of length 4, so one deletion (the b) is needed. Printing the length 5, printing the LPS 4, and adding one to the answer each give different values.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What…
- The string " hello world " is split by the Python-style rule that runs of spaces are treated as one separator and empty pieces are…
- The longest common subsequence (LCS) of "ABCBDAB" and "BDCABA" is computed by the standard table. The procedure below prints its length…
- The number of non-empty substrings of "abcd" (substrings are contiguous pieces, counted by position) is computed by the procedure below…
- The procedure below counts the uppercase letters in the sentence "Hello World From AI". What is printed? count = 0 for each character c if…
- Strings are compared by dictionary order. The procedure below counts how many of ["apple", "mango", "kiwi", "banana", "mangoes"] are…