Explore BrainMass

Language of Words:Strings, Pseudocode and Recursive Function

Consider a language of words, where each word is a string of dots and dashes. The following grammar describes this language:

< word> = < dot> | < dash> < word> | < word> < dot>
< dot> = .
< dash> = -

a) Write all three-character strings that are in this language.
b) Is the string .... in this language? Explain.
c) Write a seven-character string that contains more dashes than dots and is in the language. Show how you know that your answer is correct.
d) Write pseudocode for a recursive function isIn(str) that returns true if the string str is in this language and returns false otherwise.

Solution Preview

a) All the 1 and 2 character strings are shown below so that you can see, following the given grammar, how all the 3 character strings are generated in this language.

Single-character strings in the language:
< dot>

Two-character strings in the language:
< dash>< dot>, < dot>< dot>

Three-character strings in the language:
< dash>< dash>< dot>, < dash>< dot>< dot>, < dot>< dot>< dot>

< dash>< dot>< dot> can be generated via two routes: (< dash>< dot>) < dot> and < dash> (< ...

Solution Summary

The solution not only provides the required strings, but also gives brief explanations as to how the mentioned strings can be generated.