1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.) 1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.) 1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.) 1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.) 1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.) 1. Let X[0.. n-1] be an array of characters. A subsequence of X is a subset of not-necessarily- consecutive characters (X[i], X[i₂].....X[ik]) such that i₁ <i₂ <... <ik. A subsequence can be empty (i.e., k = 0). A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an odd number of characters. (a) Let MaxPalSub(i, j) be the length of the longest subsequence of X[i.. j] that is also a palindrome. (For simplicity, we treat X[i .. j] as empty if i>j.) Fill in the blanks to complete the following recursive definition of Max PalSub(i, j). MaxPalSub(i, j)=2+ MaxPalSub(i+1,. (MaxPalSub(i,- MaxPalSub( max if i > j if i = j if i <j and X[i]=x[j] otherwise Advice: Suppose j>i. The longest palindrome in X[i.. j] should start with X[i] and end with X[j] if X[i]=X[j]. Otherwise, it must exclude at least one of X[i] or X[j]. (b) Use dynamic programming to write a method in Java that takes as its one parameter an array x of characters and returns the length of the longest palindrome subsequence in x. Your method should be based on the above recurrence and run in O(n²) time given an array of length n. (You can handwrite or type your code. Either way, it won't actually be compiled.)
Expert Answer:
Answer rating: 100% (QA)
a MaxPalSubi j if i j 0 else if i j 1 else if Xi Xj 2 MaxPalSubi 1 j 1 else ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let A[1 n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. a. List the five inversions of the array 2, 3, 8, 6, 1. b. What array with...
-
Let A[1 .. n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. (See Problem 2-4 for more on inversions.) Suppose that each element of A...
-
Susan recently quit working for a local firm and has yet to find a new job. She knows she can maintain her health insurance from her old employer due to COBRA. How much will it likely cost her for...
-
Go to the Web site of the Federal Reserve Bank of St. Louis (FRED) (research.stlouisfed.org/fred2/) and find the most recent monthly values and values from the same month 5 years and 10 years earlier...
-
A U.S. Travel Data Center survey conducted for Better Homes and Gardens of 1500 adults found that 39% said that they would take more vacations this year than last year. Find the 95% confidence...
-
Find an example of an augmented scatterplot and click on the image. You can answer the following questions using either the default variables and cases, or else use the menu on the left to select...
-
Starting in May, Nicole has decided that she has everything that she needs to open her doors to customers. To keep up with competition, Nicole has added gift certificates and has started to advertise...
-
At the end of the accounting period, Harris Company had $6,000 of par value common stock issued, additional paid in capital of $5,500, retained earnings of $6,000, and $2,000 of treasury stock. What...
-
An increasing number of Americans are moving to a warmer climate when they retire. To take advantage of this trend, Sunny Skies Unlimited is undertaking a major real estate development project. The...
-
Jackson Instrument Company manufactures gauges for the construction industry. The company has two production departments: Machining and Finishing. There are also three support departments: Human...
-
JanehasaskedyoutomakechangestotheCompanySettingstoset upanduseadditionalQuickBooksfeatures. Jane knows that discountsare a part of the business. She asks you to make sure that when you add...
-
a) Discuss whether the system should be controllable or not. Check your intuition by forming the controllability matrix and checking its rank. b) Assume that all of the state variables can be...
-
(2) The data below is given as input values for a water-flood in a horizontal, linear reservoir. Relative permeability data in this reservoir are given as: kr = krw.max kyo = Kyo,max Fluid and...
-
Ashby plot for materials index of (E2/p), suitable for a Beam of minimum weight and prescribed stiffness. On the Log E versus Log p graph, slide the materials index line of slope 2 upwards to...
-
Use the energy method to determine the equations of motion and the natural frequencies of the systems shown in the following figures: k www 30 111 m
-
Hereunder is the Unadjusted Trial Balance of the DOT as of December 31, 2015 Account Title Debit Credit Cash Treasury/Agency Deposit, Reg 100,000 Cash - MDS, Regular 180,000 Cash TRA 70,000 Due...
-
Suppose that the electrical potential at the point (x, y, z) is E(x, y, z) = x + y - 2z. What is the direction of the acceleration at the point (1,3,2)?
-
Let f: S S be an operator on an n simplex with vertices {x0, x1,..., xn}. Suppose that the elements of S are labeled using the rule x min{i: i i, 0} where i, and i are the barycentric coordinates...
-
Let f and g be affine functionals on a linear space X, and let S X be a convex set on which g(x) 0. The function is both quasi concave and quasi convex on S. h(x) = g(x)
-
A topological space is said to be normal if, for any pair of disjoint closed sets S1 and S2, there exist open sets (neighborhoods) T1 S1 and T2 S2 such that T1 T2 = . Show that any metric space is...
-
Among your colleagues in class, identify a term or phrase italicized in this chapter that you think is the most significant from your reading. Absent team consensus, then just provide your...
-
What are the two key financial objectives in the management of a company? How can a focus on these objectives create ethical dilemmas?
-
What is the purpose of financial statements? Would you want to produce them even if they were not required, say, for entity tax reporting?
Study smarter with the SolutionInn App