Consider the language that the following grammar defines:
= $ | a a | b b | ... | y y |z z Equivalently,
L = {w$reverse(w):w is a string of letters of length ≥ 0}
Note that this language is very similar to the language of palindromes, but there is a special middle character here.
The algorithm that this chapter gave for recognizing palindromes can be adapted easily to this language. The algorithm, which is recursive and processes the string str from both ends toward the middle, is based on the following facts:
■ A string with no characters is not in the language.
■ A string with exactly one character is in the language if the character is a $.
■ A longer string is in the language if the ends are identical letters and the inner substring (from the second character to the next to the last character of str) is in the language.
Describe a recursive recognition algorithm that processes the string from left to right, reading one character at a time and not explicitly saving the string for future reference. Write a Java method that implements your algorithm.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.