Question: A palindrome is a non-empty string that reads the same forward and backward. Examples of palindromes are civic, racecar, and aibohphobia (fear of palindromes). You
A palindrome is a non-empty string that reads the same forward and backward. Examples of palindromes are "civic", "racecar", and "aibohphobia" (fear of palindromes). You are given a string as an array S(1,,n] of length n. Your goal is to find the length of the longest palindromic subsequence of a string. Note that, by definition, a subsequence can consist of non-consecutive elements. For example, for the string "character", the answer is 5 , which corresponds to the palindromic subsequence "carac". 1. Subproblems: Define appropriate subproblems MAxLengrH in words. You should explain what the entries in MAxLenGTH are intended to store. 2. Base Cases: State the base cases for MAxLENGTH and their values. 3. Recurrence: State and justify a recurrence for MaxLengrH. 4. Algorithm: Describe an algorithm that computes MAxLENGTH and outputs the length of the longest palindromic subsequence. Your algorithm should describe in simple words how the MAxLENGTH array is filled. Use pseudocode only if necessary. State and justify the run time of your algorithm as a expression
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
