Problem

Consider the language that the following grammar defines: = $ | a a | b b | ... | y y |z z...

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.

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 6
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT