ps1 Sol
ps1 Sol
1. Give a regular expression that will accept all valid names. A name consists of a
first name, an optional middle name or initial, and a last name, separated by spaces.
First, middle and last names start with a capital letter and are followed by zero or
more lowercase letters. If the name has a middle initial, instead of a middle name, it
must be a capital letter followed by a period. Examples of valid names include:
• Joe Public
• Joe Q. Public
• Joe Quincy Public
Assume that Σ (the alphabet) for the strings you are accepting is all capital letters,
all lowercase letters, and ‘.’
Answer: Assume that the character ‘ ’ represents a space. Define the following
character class (which captures any single name):
N = [A-Z][a-z]*
We can then define the language using the following regular expression:
N (N |[A-Z].)? N
Answer:
1
[a-z]
[a-z] [a-z]
[a-z] _
. _
Answer: Here is one possible solution, based on building ab∗ c and a+ bc∗ first.
2 a 3 c 4
λ
λ
1 8
a c
λ λ
5 a 6 b 7
4. Produce the deterministic equivalent of the NFA you built in question 3. Show both
the graphical representation and the tabular representation.
2
Answer: Let us proceed by the subset construction
State(s) a b c Final? New state
{1, 2, 5} {3, 6} err err No 1
{3, 6} {6} {3, 7, 8} {4, 8} No 2
{6} {6} {7, 8} err No 3
{3, 7, 8} err {3} {4, 7, 8} Yes 4
{4, 8} err err err Yes 5
{7, 8} err err {7, 8} Yes 6
{3} err {3} {4, 8} No 7
{4, 7, 8} err err {7, 8} Yes 8
The graphical representation is given below:
b
a
2 a 3 4
a c
c b b
1 8
5 6 7
c b
c
3
Note that it doesn’t matter that 3 transitions to 6 on b, but not 8. Once you’re in 6
or 8, the two states behave the same.
7. Can the language (k g )k for one particular k be recognized by an FSA? Why or why
not?
Yes, it can. We can use k states to recognize the ‘(’s, one state to recognize the ‘g’,
and k more states to recognize the ‘)’s.