Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Dynamic Programming This problem will walk you through the steps of designing a dynamic program. The problem we are solving is the longest palindrome

image text in transcribed

2. Dynamic Programming This problem will walk you through the steps of designing a dynamic program. The problem we are solving is the longest palindrome problem: given a string, S, what is the length of the longest palindrome that is a substring of S? A palindrome is a string that reads the same forwards as backwards. For example, "racecar", "eve", and "T", are all palindromes. We also consider the empty string to be a palindrome (of length 0). (a) First we need to figure out what our subproblems are. Since we are working with strings, a natural subproblem starting at index i. Write an expression for the recursive case of OPT(i,n). (Hint: All palindromes above a certain size have palindromes as substrings). (b) Next we need a base case for our OPT recurrence. Write an expression for the base case(s) of this recurrence. Hint: Which size strings are always palindromes?) (c) Now that we have a complete recurrence, we need to figure out which order to solve the subproblems in. Which subproblems does the recursive case OPT(i, n) require to be calculated before it can be solved? (d) Given these dependencies, what order should we loop over the subproblem in? (e) We have all of the pieces required to put together a dynamic program now. Write psuedocode for the dynamic program that computes the length of the longest palindromic substring of S

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

You can NOT create a Series from NumPy Arrays

Answered: 1 week ago