This problem will walk you through the steps of designing a dynamic program. The problem we...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 "1", 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 to use is substrings. Let OPT(i, n) denote the length of the longest palindrome in the substring of length in 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. 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 "1", 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 to use is substrings. Let OPT(i, n) denote the length of the longest palindrome in the substring of length in 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.
Expert Answer:
Answer rating: 100% (QA)
a The recursive case for OPTi n can be expressed as follows if Si Si n 1 The first and last characters of the substring match OPTi n 2 OPTi 1 n 2 if n ... View the full answer
Related Book For
Algorithm Design And Applications
ISBN: 9781118335918
1st Edition
Authors: Michael T. Goodrich, Roberto Tamassia
Posted Date:
Students also viewed these algorithms questions
-
Q1 A semi-circular steel gate is installed in the side of a water storage reservoir that has a side slope of 50 as shown in figure Q1. The gate has a radius of 3m and the top of the gate is supported...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
If you deposit $2,000 today into an account earning an annual rate of return of 9 percent, what would your account be worth In 30 years? a. If you deposit $2, 000 today into an account earning an...
-
Whipple Company has 1,000,000 shares of common stock authorized with a par value of $3 per share, of which 600,000 shares are outstanding. When the market value was $8 per share, Whipple issued a...
-
a. Consider the effect of population growth on the allocation on the dynamic efficient allocation of a depletable resource across time. Suppose we have two versions of the two-period model, discussed...
-
In an Internet giveaway, every 130 th person who submits a survey receives \(\$ 250\), and every 900 th person receives a free cell phone. How many submissions must be received for the first person...
-
Harding Corporation has the following accounts included in its December 31, 2012, trial balance: Accounts Receivable $110,000; Inventory $290,000; Allowance for Doubtful Accounts $8,000; Patents...
-
P 8-19 (similar to) Question Help Innovation Company is thinking about marketing a new software product. Upfront costs to market and develop the product are $4 97 million. The product is expected to...
-
Buckeye Manufacturing produces heads for engines used in the manufacture of trucks. The production line is highly complex, and it measures 900 feet in length. Two types of engine heads are produced...
-
A power screw with a single ACME thread has a mean diameter of 33 mm and a pitch of 5 mm. The coefficient of thread friction is 0.16 and the coefficient of collar friction is 0.12. The collar's mean...
-
A plane dives at 27 to the horizontal and releases a package at an altitude of 430 m. If the load is in the air for 4.8 s, find: a) the speed of the plane when it released the package; m/s b) the...
-
3) Chris made a $10,000 loan, bearing interest at 12%, to a friend. Chris directed the friend to pay the interest to Chris's 15-year-old daughter. During the current year, the daughter received...
-
A baseball seen the past upward by window with a vertical speed of 16 m/s. If the ball is thrown by a person, 21 m below the street, (a) what was its initial speed, (b) what altitude does it...
-
An assessment of goodwill impairment is conducted by the management. The goodwill is resulted from previous mergers and acquisitions. During the impairment testing, a discounted cash flow (DCF) is...
-
Provide a peer response to the following discussion post below on net income and cash flows. Point out what you perceived to be the strengths of the initial posting along with supporting rationale....
-
The Assignment: Your team of transportation specialists has been hired by Atco Structures (Calgary) to determine the most efficient, least cost transportation options to move these structures from...
-
The swap spread is the difference between the swap rate and the equivalent-maturity Treasury bond yield. Explain why a widening swap spread may be a signal of deteriorating economic conditions. Plot...
-
For each of the regions shown in Figure 26.8, give an LP for which that region is the feasible region, or explain why no such linear program exists. Figure 26.8 X2 X2 6. 6. 6. 4 2 2 4 (a) (b) (c)...
-
In applications involving the use of quadtrees in memory-constrained devices, such as smartphones, we often want to optimize the data structure to make it more space efficient. One obvious...
-
Using the definition of a c-incremental algorithm from the previous exercise, show that, if a c-incremental algorithm A has a worst-case running time t(N) in the RAM model, as a function of the...
-
You have been asked to value the practice of Dr. Vong, a pediatrician in your town, and are provided with the following facts: The practice generated $800,000 in revenues last year, and these...
-
You are trying to decide how much you should bid on a Ken Griffey Jr. rookie baseball card in good condition on eBay. You notice that there have been eight transactions involving Ken Griffey Jr....
-
A company is considering delaying a project with after-tax cash flows of \($25\) million but that costs \($300\) million to take on (the life of the project is 20 years, and the cost of capital is...
Study smarter with the SolutionInn App