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
  1. A. 5
  2. B. 4
  3. C. 2
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic