SlideShare a Scribd company logo
1 of 11
Download to read offline
CS 341: Foundations of Computer Science II
Prof. Marvin Nakayama
Homework 3 Solutions
1. Give NFAs with the specified number of states recognizing each of the following lan-
guages. In all cases, the alphabet is Σ = {0, 1}.
(a) The language { w ∈ Σ∗
| w ends with 00 } with three states.
1 2 3
0, 1
0 0
(b) The language { w ∈ Σ∗
| w contains the substring 0101, i.e., w = x0101y for
some x, y ∈ Σ∗
} with five states.
1 2 3 4 5
0, 1
0 1 0 1
0, 1
(c) The language { w ∈ Σ∗
| w contains at least two 0s, or exactly two 1s } with six
states.
1
2
5
3 4
60
ε
0, 1
0
1
0
0, 1
1
0
1
0
(d) The language {ε} with one state.
1
1
(e) The language 0∗
1∗
0∗
0 with three states.
1 2 3
0
ε
1
0
0
2. (a) Show by giving an example that, if M is an NFA that recognizes language C,
swapping the accept and non-accept states in M doesn’t necessarily yield a new
NFA that recognizes C.
Answer:
The NFA M below recognizes the language C = { w ∈ Σ∗
| w ends with 00 },
where Σ = {0, 1}.
1 2 3
0, 1
0 0
Swapping the accept and non-accept states of M gives the following NFA M′
:
1 2 3
0, 1
0 0
Note that M′
accepts the string 100 ∈ C = { w | w does not end with 00 }, so
M′
does not recognize the language C.
(b) Is the class of languages recognized by NFAs closed under complement? Explain
your answer.
Answer:
The class of languages recognized by NFAs is closed under complement, which we
can prove as follows. Suppose that C is a language recognized by some NFA M,
i.e., C = L(M). Since every NFA has an equivalent DFA (Theorem 1.39), there
is a DFA D such that L(D) = L(M) = C. By problem 3 on Homework 2, we
then know there is another DFA D that recognizes the language L(D). Since
2
every DFA is also an NFA, this then shows that there is an NFA, in particular D,
that recognizes the language C = L(D). Thus, the class of languages recognized
by NFAs is closed under complement.
3. Use the construction given in Theorem 1.39 to convert the following NFA N into an
equivalent DFA.
1 2
3
ε
a
a
a, b
b
Answer: Let NFA N = (Q, Σ, δ, 1, F ), where Q = {1, 2, 3}, Σ = {a, b}, 1 is
the start state, F = {2}, and the transition function δ as in the diagram of N.
To construct a DFA M = (Q′
, Σ, δ′
, q′
0, F ′
) that is equivalent to NFA N, first we
compute the ε-closure of every subset of Q = {1, 2, 3}.
Set R ⊆ Q ε-closure E(R)
∅ ∅
{1} {1, 2}
{2} {2}
{3} {3}
{1, 2} {1, 2}
{1, 3} {1, 2, 3}
{2, 3} {2, 3}
{1, 2, 3} {1, 2, 3}
Then define Q′
= P(Q), so
Q′
= { ∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} }.
The start state of M is then E({1}) = {1, 2}. The set of accept states of M is
F ′
= { {2}, {1, 2}, {2, 3}, {1, 2, 3} }.
We define the transitions in the DFA M as in the following diagram:
3
{1, 2}
{2, 3}
∅
{1, 2, 3}a
b
a b
a, b
b
a
Note that we left out some of the states (e.g., {1}) in P(Q) from our diagram of the
DFA M since they are not accessible from the start state {1, 2}. Also, we had to add
an arc from state ∅ to itself labelled with “a, b” so that this state has an arc leaving it
corresponding to each symbol in the alphabet Σ, which is a requirement for any DFA.
The algorithm given in the notes and textbook will always correctly construct an
equivalent DFA from a given NFA, but we don’t always have to go through all the
steps of the algorithm to obtain an equivalent DFA. For example, on this problem, we
begin by figuring out what states the NFA can be in without reading any symbols. In
this case, this is E({1}) = {1, 2} since 1 is the starting state of the NFA, and the
NFA can jump from 1 to 2 without reading any symbols by taking the ε-transition.
Thus, we first create a DFA state corresponding to the set {1, 2}:
{1, 2}
The state {1, 2} is the start state of the DFA since this is where the NFA can be
without reading any symbols. The state {1, 2} is also an accepting state for the DFA
since it contains 2, which is accepting for the NFA.
Now for DFA state {1, 2}, determine where the NFA can go on an a from each NFA
state within this DFA state, and where the NFA can go on a b from each NFA state
within this DFA state. On an a, the NFA can go from state 1 to state 3; also, the
NFA can go from state 2 to 1, and then it also can go further from 1 to 2 on the ε.
So from NFA states 1 and 2 on an a, the NFA can end up in states 1, 2, and 3, so
draw a transition in the DFA from state {1, 2} to a new state {1, 2, 3}, which is an
accepting state since it contains 2 ∈ F :
4
{1, 2} {1, 2, 3}a
Similarly, to determine where the DFA moves on b from DFA state {1, 2}, determine
all the possibilities of where the NFA can go from NFA states 1 and 2 on b. From
state 1, the NFA can’t go anywhere on a b; also, the NFA can’t go anywhere from
state 2 on b. Thus, the NFA can’t go anywhere from states 2 and 3 on a b, so we add
a b-edge in the DFA from state {1, 2} to a new DFA state ∅, which is not accepting
since it contains no accept states of the NFA:
{1, 2}
∅
{1, 2, 3}a
b
Now every time we add a new DFA state, we have to determine all the possibilities of
where the NFA can go on an a from each NFA state within that DFA state, and where
the NFA can go on a b from each NFA state within that DFA state. For DFA state
{1, 2, 3}, we next determine where the NFA can go on an a from each of the NFA
states 1, 2 and 3. From NFA state 1, the NFA on an a can go to NFA state 3; from
NFA state 2, the NFA on an a can go to NFA state 1, and then it can also further
jump to 2 on ε; from NFA state 3, the NFA on an a can go to NFA state 2. Thus, if
the NFA is in states 1, 2 and 3, it can go on an a to states 1, 2 and 3, so we add to
the DFA an a-edge from {1, 2, 3} to {1, 2, 3}.
{1, 2}
∅
{1, 2, 3}a
b
a
Now we determine where the b-edge from DFA state {1, 2, 3} goes to. To do this,
we examine what happens to the NFA from states 1, 2 and 3 on a b. If the NFA is
in state 1, then there is nowhere to go on a b; if the NFA is in state 2, then there is
nowhere to go on a b; if the NFA is in state 3, then the NFA can go to 2 or 3 on b.
Hence, if the NFA is in states 1, 2 and 3, the NFA on b can end in states 2 and 3.
Thus, in the DFA, draw an edge from state {1, 2, 3} to a new state {2, 3}, which is
accepting since it contains 2 ∈ F :
5
{1, 2}
{2, 3}
∅
{1, 2, 3}a
b
b
a
Now do the same for DFA states {2, 3} and ∅. If any new DFA states arise, then we
need to determine the a and b transitions out of those states as well. We stop once
every DFA state has an a-transition and a b-transition out of it. Accepting states
in the DFA are any DFA states that contain at least one accepting NFA state. We
eventually end up with the DFA below as before:
{1, 2}
{2, 3}
∅
{1, 2, 3}a
b
a b
a, b
b
a
For the DFA state ∅, there are no versions of the NFA currently active, i.e., all “threads”
have “crashed,” so the NFA cannot proceed and the input string will not be accepted.
However, according to the definition of a DFA, each state must have edges leaving it
corresponding to each symbol in the alphabet Σ. Thus, we add a loop from the DFA
state ∅ back to itself labeled with Σ, which in our case is a, b.
4. Give regular expressions that generate each of the following languages. In all cases,
the alphabet is Σ = {a, b}.
6
(a) The language { w ∈ Σ∗
| |w| is odd }.
Answer: (a ∪ b)((a ∪ b)(a ∪ b))∗
(b) The language { w ∈ Σ∗
| w has an odd number of a’s }.
Answer: b∗
a(ab∗
a ∪ b)∗
(c) The language { w | w contains at least two a’s, or exactly two b’s }.
Answer: b∗
ab∗
a(a ∪ b)∗
∪ a∗
ba∗
ba∗
(d) The language { w ∈ Σ∗
| w ends in a double letter }. (A string contains a double
letter if it contains aa or bb as a substring.)
Answer: (a ∪ b)∗
(aa ∪ bb)
(e) The language { w ∈ Σ∗
| w does not end in a double letter }.
Answer: ε ∪ a ∪ b ∪ (a ∪ b)∗
(ab ∪ ba)
(f) The language { w ∈ Σ∗
| w contains exactly one double letter }. For example,
baaba has exactly one double letter, but baaaba has two double letters.
Answer: (ε ∪ b)(ab)∗
aa(ba)∗
(ε ∪ b) ∪ (ε ∪ a)(ba)∗
bb(ab)∗
(ε ∪ a)
5. Suppose we define a restricted version of the Java programming language in which
variable names must satisfy all of the following conditions:
A variable name can only use Roman letters (i.e., a, b, . . . , z, A, B, . . . , Z) or
Arabic numerals (i.e., 0, 1, 2, . . . , 9); i.e., underscore and dollar sign are not
allowed.
A variable name must start with a Roman letter: a, b, . . . , z, A, B, . . . , Z
The length of a variable name must be no greater than 8.
A variable name cannot be a keyword (e.g., if). The set of keywords is finite.
Let L be the set of all valid variable names in our restricted version of Java.
(a) Let L0 be the set of strings satisfying the first 3 conditions above; i.e., we do not
require the last condition. Give a regular expression for L0.
Answer: To simplify the regular expression, we define
Σ1 = {a, b, . . . , z, A, B, . . . , Z}
Σ2 = {0, 1, 2, . . . , 9}.
Then a regular expression for L0 is
Σ1 (Σ1 ∪ Σ2 ∪ ε) · · · (Σ1 ∪ Σ2 ∪ ε)
7 times
.
Note that by including the ε in each of the last parts, we can generate strings
that have length strictly less than 8.
7
(b) Prove that L has a regular expression, where L is the set of strings satisfying all
four conditions.
Answer: We proved in Homework 1, problem 4(b), that L is finite. Thus, L is
regular, so it has a regular expression. Although the problem didn’t ask for it, we
can write a regular expression for L by listing all of the strings in L and putting
a ∪ in between each pair of consecutive strings. This works because L is finite.
(c) Give a DFA for the language L0 in part (a), where the alphabet Σ is the set of
all printable characters on a computer keyboard (no control characters), except
for parentheses to avoid confusion.
Answer: Define Σ1 and Σ2 as in part (a), and let Σ3 = Σ − (Σ1 ∪ Σ2) be all
of the other characters on a computer keyboard except for parentheses. Then a
DFA for L0 is as follows:
1 2 3 4 9
0
Σ1
Σ2 ∪ Σ3
Σ1 ∪ Σ2
Σ3
Σ1 ∪ Σ2
Σ3
• • •
Σ3
Σ
Σ
6. Define L to be the set of strings that represent numbers in a modified version of Java.
The goal in this problem is to define a regular expression and an NFA for L. To
precisely define L, let the set of digits be Σ1 = { 0, 1, 2, . . . , 9 }, and define the set
of signs to be Σ2 = { +, - }. Then L = L1 ∪ L2 ∪ L3, where
L1 is the set of all strings that are decimal integer numbers. Specifically, L1
consists of strings that start with an optional sign, followed by one or more digits.
Examples of strings in L1 are “02”, “+9”, and “-241”.
L2 is the set of all strings that are floating-point numbers that are not in expo-
nential notation. Specifically, L2 consists of strings that start with an optional
sign, followed by zero or more digits, followed by a decimal point, and end with
zero or more digits, where there must be at least one digit in the string. Examples
of strings in L2 are “13.231”, “-28.” and “.124”. All strings in L2 have exactly
one decimal point.
L3 is the set of all strings that are floating-point numbers in exponential notation.
Specifically, L3 consists of strings that start with a string from L1 or L2, followed
by “E” or “e”, and end with a string from L1. Examples of strings in L3 are
“-80.1E-083”, “+8.E5” and “1e+31”.
Assume that there is no limit on the number of digits in a string in L. Also, we do
not allow for the suffixes L, l, F, f, D, d, at the end of numbers to denote types (long
integers, floats, and doubles). Define Σ as the alphabet of all printable characters on a
computer keyboard (no control characters), except for parentheses to avoid confusion.
8
(a) Give a regular expression for L1. Also, give an NFA and a DFA for L1 over the
alphabet Σ.
Answer: A regular expression for L1 is
R1 = ( + ∪ - ∪ ε ) Σ1 Σ∗
1
where Σ1 = { 0, 1, 2, . . . , 9 } as previously defined. An NFA for L1 is
q1 q2 q3
+, -, ε Σ1
Σ1
Define Σ3 = Σ − (Σ1 ∪ Σ2) with Σ2 = { -, + }, as before. Then a DFA for
L1 is
1 2
3
4
Σ2
Σ1
Σ1
Σ − Σ1
Σ − Σ1
Σ1
Σ3
Σ
Notice that the DFA is more complicated than the NFA.
(b) Give a regular expression for L2. Also, give an NFA for L2 over the alphabet Σ.
Answer: A regular expression for L2 is
R2 = ( + ∪ - ∪ ε )(Σ1 Σ∗
1 . Σ∗
1 ∪ . Σ1 Σ∗
1)
Note that the regular expression ( + ∪ - ∪ ε ) Σ∗
1 . Σ∗
1 is not correct since it
can generate the strings “.”, “+.” and “-.”, which are not valid floating-point
numbers.
An NFA for L2 is
r1 r2
r3
r4
r5
+, -, ε
Σ1
•
•
Σ1
Σ1
Σ1
9
(c) Give a regular expression for L3. Also, give an NFA for L3 over the alphabet Σ.
Answer: A regular expression for L3 is
R3 = (R1 ∪ R2) (E ∪ e) R1
where R1 and R2 are defined in the previous parts. An NFA for L3 is
s1 s2
s3
s4 s5 s6 s7 s8
+, -, ε
Σ1
•
Σ1
•
Σ1
Σ1
Σ1
E, e +, -, ε Σ1
Σ1
(d) Give a regular expression for the language L. Also, give an NFA for L over the
alphabet Σ.
Answer: Note that L = L1 ∪ L2 ∪ L3, so a regular expression for L is
R4 = R1 ∪ R2 ∪ R3
We can construct an NFA for L by taking the union of the NFA’s for L1, L2 and
L3, as follows:
10
q1 q2 q3
+, -, ε Σ1
Σ1
r1 r2
r3
r4
r5
+, -, ε
Σ1
•
•
Σ1
Σ1
Σ1
s1 s2
s3
s4 s5 s6 s7 s8
+, -, ε
Σ1
•
Σ1
•
Σ1
Σ1
Σ1
E, e +, -, ε Σ1
Σ1
q0
ε
ε
ε
A simpler NFA for L is to take the NFA for L3 and make s3 and s5 also accepting
states in addition to s8.
11

More Related Content

What's hot (19)

Lesson 08
Lesson 08Lesson 08
Lesson 08
 
Theory of Automata Lesson 01
 Theory of Automata Lesson 01  Theory of Automata Lesson 01
Theory of Automata Lesson 01
 
Theory of Automata Lesson 02
Theory of Automata Lesson 02Theory of Automata Lesson 02
Theory of Automata Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lesson 09
Lesson 09Lesson 09
Lesson 09
 
Regular expressions and languages pdf
Regular expressions and languages pdfRegular expressions and languages pdf
Regular expressions and languages pdf
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 3,4
Lecture 3,4Lecture 3,4
Lecture 3,4
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
Context free languages
Context free languagesContext free languages
Context free languages
 
context free language
context free languagecontext free language
context free language
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 

Similar to Hwsoln03 toc

Chapter 2 limits of DFA NDFA.ppt
Chapter 2  limits of DFA  NDFA.pptChapter 2  limits of DFA  NDFA.ppt
Chapter 2 limits of DFA NDFA.pptArwaKhallouf
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaRushabh2428
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdfAbrar11535
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Dr. Maamoun Ahmed
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfSergioUlisesRojasAla
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2bolovv
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Srimatre K
 
Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1bolovv
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsRushabh2428
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...parmeet834
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxRaviAr5
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfdawod yimer
 

Similar to Hwsoln03 toc (20)

Nfa vs dfa
Nfa vs dfaNfa vs dfa
Nfa vs dfa
 
Chapter 2 limits of DFA NDFA.ppt
Chapter 2  limits of DFA  NDFA.pptChapter 2  limits of DFA  NDFA.ppt
Chapter 2 limits of DFA NDFA.ppt
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdf
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5
 
Nondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdfNondeterministic Finite Automata AFN.pdf
Nondeterministic Finite Automata AFN.pdf
 
Chapter 2 2 1 2
Chapter 2 2 1 2Chapter 2 2 1 2
Chapter 2 2 1 2
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1
 
Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S... Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
Introduction to the Theory of Computation, Winter 2003 A. Hevia and J. Mao S...
 
draft
draftdraft
draft
 
5.ppt
5.ppt5.ppt
5.ppt
 
automata problems
automata problemsautomata problems
automata problems
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Mod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptxMod 2_RegularExpressions.pptx
Mod 2_RegularExpressions.pptx
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdf
 
CS 5th.pptx
CS 5th.pptxCS 5th.pptx
CS 5th.pptx
 

More from parmeet834

Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata parmeet834
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...parmeet834
 
Graph representation of DFA’s Da
Graph representation of DFA’s DaGraph representation of DFA’s Da
Graph representation of DFA’s Daparmeet834
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automataparmeet834
 
Pushdown Automata
Pushdown AutomataPushdown Automata
Pushdown Automataparmeet834
 
Assignment Theory of computation TOC
Assignment Theory of computation TOCAssignment Theory of computation TOC
Assignment Theory of computation TOCparmeet834
 
5 decidability theory of computation
5 decidability theory of computation 5 decidability theory of computation
5 decidability theory of computation parmeet834
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)parmeet834
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
 
Finite Automata
Finite AutomataFinite Automata
Finite Automataparmeet834
 
1 introduction
1 introduction1 introduction
1 introductionparmeet834
 

More from parmeet834 (12)

DFA
DFA DFA
DFA
 
Nondeterministic Finite Automata
Nondeterministic Finite Automata Nondeterministic Finite Automata
Nondeterministic Finite Automata
 
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
 
Graph representation of DFA’s Da
Graph representation of DFA’s DaGraph representation of DFA’s Da
Graph representation of DFA’s Da
 
Pushdown automata
Pushdown automataPushdown automata
Pushdown automata
 
Pushdown Automata
Pushdown AutomataPushdown Automata
Pushdown Automata
 
Assignment Theory of computation TOC
Assignment Theory of computation TOCAssignment Theory of computation TOC
Assignment Theory of computation TOC
 
5 decidability theory of computation
5 decidability theory of computation 5 decidability theory of computation
5 decidability theory of computation
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
1 introduction
1 introduction1 introduction
1 introduction
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Hwsoln03 toc

  • 1. CS 341: Foundations of Computer Science II Prof. Marvin Nakayama Homework 3 Solutions 1. Give NFAs with the specified number of states recognizing each of the following lan- guages. In all cases, the alphabet is Σ = {0, 1}. (a) The language { w ∈ Σ∗ | w ends with 00 } with three states. 1 2 3 0, 1 0 0 (b) The language { w ∈ Σ∗ | w contains the substring 0101, i.e., w = x0101y for some x, y ∈ Σ∗ } with five states. 1 2 3 4 5 0, 1 0 1 0 1 0, 1 (c) The language { w ∈ Σ∗ | w contains at least two 0s, or exactly two 1s } with six states. 1 2 5 3 4 60 ε 0, 1 0 1 0 0, 1 1 0 1 0 (d) The language {ε} with one state. 1
  • 2. 1 (e) The language 0∗ 1∗ 0∗ 0 with three states. 1 2 3 0 ε 1 0 0 2. (a) Show by giving an example that, if M is an NFA that recognizes language C, swapping the accept and non-accept states in M doesn’t necessarily yield a new NFA that recognizes C. Answer: The NFA M below recognizes the language C = { w ∈ Σ∗ | w ends with 00 }, where Σ = {0, 1}. 1 2 3 0, 1 0 0 Swapping the accept and non-accept states of M gives the following NFA M′ : 1 2 3 0, 1 0 0 Note that M′ accepts the string 100 ∈ C = { w | w does not end with 00 }, so M′ does not recognize the language C. (b) Is the class of languages recognized by NFAs closed under complement? Explain your answer. Answer: The class of languages recognized by NFAs is closed under complement, which we can prove as follows. Suppose that C is a language recognized by some NFA M, i.e., C = L(M). Since every NFA has an equivalent DFA (Theorem 1.39), there is a DFA D such that L(D) = L(M) = C. By problem 3 on Homework 2, we then know there is another DFA D that recognizes the language L(D). Since 2
  • 3. every DFA is also an NFA, this then shows that there is an NFA, in particular D, that recognizes the language C = L(D). Thus, the class of languages recognized by NFAs is closed under complement. 3. Use the construction given in Theorem 1.39 to convert the following NFA N into an equivalent DFA. 1 2 3 ε a a a, b b Answer: Let NFA N = (Q, Σ, δ, 1, F ), where Q = {1, 2, 3}, Σ = {a, b}, 1 is the start state, F = {2}, and the transition function δ as in the diagram of N. To construct a DFA M = (Q′ , Σ, δ′ , q′ 0, F ′ ) that is equivalent to NFA N, first we compute the ε-closure of every subset of Q = {1, 2, 3}. Set R ⊆ Q ε-closure E(R) ∅ ∅ {1} {1, 2} {2} {2} {3} {3} {1, 2} {1, 2} {1, 3} {1, 2, 3} {2, 3} {2, 3} {1, 2, 3} {1, 2, 3} Then define Q′ = P(Q), so Q′ = { ∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} }. The start state of M is then E({1}) = {1, 2}. The set of accept states of M is F ′ = { {2}, {1, 2}, {2, 3}, {1, 2, 3} }. We define the transitions in the DFA M as in the following diagram: 3
  • 4. {1, 2} {2, 3} ∅ {1, 2, 3}a b a b a, b b a Note that we left out some of the states (e.g., {1}) in P(Q) from our diagram of the DFA M since they are not accessible from the start state {1, 2}. Also, we had to add an arc from state ∅ to itself labelled with “a, b” so that this state has an arc leaving it corresponding to each symbol in the alphabet Σ, which is a requirement for any DFA. The algorithm given in the notes and textbook will always correctly construct an equivalent DFA from a given NFA, but we don’t always have to go through all the steps of the algorithm to obtain an equivalent DFA. For example, on this problem, we begin by figuring out what states the NFA can be in without reading any symbols. In this case, this is E({1}) = {1, 2} since 1 is the starting state of the NFA, and the NFA can jump from 1 to 2 without reading any symbols by taking the ε-transition. Thus, we first create a DFA state corresponding to the set {1, 2}: {1, 2} The state {1, 2} is the start state of the DFA since this is where the NFA can be without reading any symbols. The state {1, 2} is also an accepting state for the DFA since it contains 2, which is accepting for the NFA. Now for DFA state {1, 2}, determine where the NFA can go on an a from each NFA state within this DFA state, and where the NFA can go on a b from each NFA state within this DFA state. On an a, the NFA can go from state 1 to state 3; also, the NFA can go from state 2 to 1, and then it also can go further from 1 to 2 on the ε. So from NFA states 1 and 2 on an a, the NFA can end up in states 1, 2, and 3, so draw a transition in the DFA from state {1, 2} to a new state {1, 2, 3}, which is an accepting state since it contains 2 ∈ F : 4
  • 5. {1, 2} {1, 2, 3}a Similarly, to determine where the DFA moves on b from DFA state {1, 2}, determine all the possibilities of where the NFA can go from NFA states 1 and 2 on b. From state 1, the NFA can’t go anywhere on a b; also, the NFA can’t go anywhere from state 2 on b. Thus, the NFA can’t go anywhere from states 2 and 3 on a b, so we add a b-edge in the DFA from state {1, 2} to a new DFA state ∅, which is not accepting since it contains no accept states of the NFA: {1, 2} ∅ {1, 2, 3}a b Now every time we add a new DFA state, we have to determine all the possibilities of where the NFA can go on an a from each NFA state within that DFA state, and where the NFA can go on a b from each NFA state within that DFA state. For DFA state {1, 2, 3}, we next determine where the NFA can go on an a from each of the NFA states 1, 2 and 3. From NFA state 1, the NFA on an a can go to NFA state 3; from NFA state 2, the NFA on an a can go to NFA state 1, and then it can also further jump to 2 on ε; from NFA state 3, the NFA on an a can go to NFA state 2. Thus, if the NFA is in states 1, 2 and 3, it can go on an a to states 1, 2 and 3, so we add to the DFA an a-edge from {1, 2, 3} to {1, 2, 3}. {1, 2} ∅ {1, 2, 3}a b a Now we determine where the b-edge from DFA state {1, 2, 3} goes to. To do this, we examine what happens to the NFA from states 1, 2 and 3 on a b. If the NFA is in state 1, then there is nowhere to go on a b; if the NFA is in state 2, then there is nowhere to go on a b; if the NFA is in state 3, then the NFA can go to 2 or 3 on b. Hence, if the NFA is in states 1, 2 and 3, the NFA on b can end in states 2 and 3. Thus, in the DFA, draw an edge from state {1, 2, 3} to a new state {2, 3}, which is accepting since it contains 2 ∈ F : 5
  • 6. {1, 2} {2, 3} ∅ {1, 2, 3}a b b a Now do the same for DFA states {2, 3} and ∅. If any new DFA states arise, then we need to determine the a and b transitions out of those states as well. We stop once every DFA state has an a-transition and a b-transition out of it. Accepting states in the DFA are any DFA states that contain at least one accepting NFA state. We eventually end up with the DFA below as before: {1, 2} {2, 3} ∅ {1, 2, 3}a b a b a, b b a For the DFA state ∅, there are no versions of the NFA currently active, i.e., all “threads” have “crashed,” so the NFA cannot proceed and the input string will not be accepted. However, according to the definition of a DFA, each state must have edges leaving it corresponding to each symbol in the alphabet Σ. Thus, we add a loop from the DFA state ∅ back to itself labeled with Σ, which in our case is a, b. 4. Give regular expressions that generate each of the following languages. In all cases, the alphabet is Σ = {a, b}. 6
  • 7. (a) The language { w ∈ Σ∗ | |w| is odd }. Answer: (a ∪ b)((a ∪ b)(a ∪ b))∗ (b) The language { w ∈ Σ∗ | w has an odd number of a’s }. Answer: b∗ a(ab∗ a ∪ b)∗ (c) The language { w | w contains at least two a’s, or exactly two b’s }. Answer: b∗ ab∗ a(a ∪ b)∗ ∪ a∗ ba∗ ba∗ (d) The language { w ∈ Σ∗ | w ends in a double letter }. (A string contains a double letter if it contains aa or bb as a substring.) Answer: (a ∪ b)∗ (aa ∪ bb) (e) The language { w ∈ Σ∗ | w does not end in a double letter }. Answer: ε ∪ a ∪ b ∪ (a ∪ b)∗ (ab ∪ ba) (f) The language { w ∈ Σ∗ | w contains exactly one double letter }. For example, baaba has exactly one double letter, but baaaba has two double letters. Answer: (ε ∪ b)(ab)∗ aa(ba)∗ (ε ∪ b) ∪ (ε ∪ a)(ba)∗ bb(ab)∗ (ε ∪ a) 5. Suppose we define a restricted version of the Java programming language in which variable names must satisfy all of the following conditions: A variable name can only use Roman letters (i.e., a, b, . . . , z, A, B, . . . , Z) or Arabic numerals (i.e., 0, 1, 2, . . . , 9); i.e., underscore and dollar sign are not allowed. A variable name must start with a Roman letter: a, b, . . . , z, A, B, . . . , Z The length of a variable name must be no greater than 8. A variable name cannot be a keyword (e.g., if). The set of keywords is finite. Let L be the set of all valid variable names in our restricted version of Java. (a) Let L0 be the set of strings satisfying the first 3 conditions above; i.e., we do not require the last condition. Give a regular expression for L0. Answer: To simplify the regular expression, we define Σ1 = {a, b, . . . , z, A, B, . . . , Z} Σ2 = {0, 1, 2, . . . , 9}. Then a regular expression for L0 is Σ1 (Σ1 ∪ Σ2 ∪ ε) · · · (Σ1 ∪ Σ2 ∪ ε) 7 times . Note that by including the ε in each of the last parts, we can generate strings that have length strictly less than 8. 7
  • 8. (b) Prove that L has a regular expression, where L is the set of strings satisfying all four conditions. Answer: We proved in Homework 1, problem 4(b), that L is finite. Thus, L is regular, so it has a regular expression. Although the problem didn’t ask for it, we can write a regular expression for L by listing all of the strings in L and putting a ∪ in between each pair of consecutive strings. This works because L is finite. (c) Give a DFA for the language L0 in part (a), where the alphabet Σ is the set of all printable characters on a computer keyboard (no control characters), except for parentheses to avoid confusion. Answer: Define Σ1 and Σ2 as in part (a), and let Σ3 = Σ − (Σ1 ∪ Σ2) be all of the other characters on a computer keyboard except for parentheses. Then a DFA for L0 is as follows: 1 2 3 4 9 0 Σ1 Σ2 ∪ Σ3 Σ1 ∪ Σ2 Σ3 Σ1 ∪ Σ2 Σ3 • • • Σ3 Σ Σ 6. Define L to be the set of strings that represent numbers in a modified version of Java. The goal in this problem is to define a regular expression and an NFA for L. To precisely define L, let the set of digits be Σ1 = { 0, 1, 2, . . . , 9 }, and define the set of signs to be Σ2 = { +, - }. Then L = L1 ∪ L2 ∪ L3, where L1 is the set of all strings that are decimal integer numbers. Specifically, L1 consists of strings that start with an optional sign, followed by one or more digits. Examples of strings in L1 are “02”, “+9”, and “-241”. L2 is the set of all strings that are floating-point numbers that are not in expo- nential notation. Specifically, L2 consists of strings that start with an optional sign, followed by zero or more digits, followed by a decimal point, and end with zero or more digits, where there must be at least one digit in the string. Examples of strings in L2 are “13.231”, “-28.” and “.124”. All strings in L2 have exactly one decimal point. L3 is the set of all strings that are floating-point numbers in exponential notation. Specifically, L3 consists of strings that start with a string from L1 or L2, followed by “E” or “e”, and end with a string from L1. Examples of strings in L3 are “-80.1E-083”, “+8.E5” and “1e+31”. Assume that there is no limit on the number of digits in a string in L. Also, we do not allow for the suffixes L, l, F, f, D, d, at the end of numbers to denote types (long integers, floats, and doubles). Define Σ as the alphabet of all printable characters on a computer keyboard (no control characters), except for parentheses to avoid confusion. 8
  • 9. (a) Give a regular expression for L1. Also, give an NFA and a DFA for L1 over the alphabet Σ. Answer: A regular expression for L1 is R1 = ( + ∪ - ∪ ε ) Σ1 Σ∗ 1 where Σ1 = { 0, 1, 2, . . . , 9 } as previously defined. An NFA for L1 is q1 q2 q3 +, -, ε Σ1 Σ1 Define Σ3 = Σ − (Σ1 ∪ Σ2) with Σ2 = { -, + }, as before. Then a DFA for L1 is 1 2 3 4 Σ2 Σ1 Σ1 Σ − Σ1 Σ − Σ1 Σ1 Σ3 Σ Notice that the DFA is more complicated than the NFA. (b) Give a regular expression for L2. Also, give an NFA for L2 over the alphabet Σ. Answer: A regular expression for L2 is R2 = ( + ∪ - ∪ ε )(Σ1 Σ∗ 1 . Σ∗ 1 ∪ . Σ1 Σ∗ 1) Note that the regular expression ( + ∪ - ∪ ε ) Σ∗ 1 . Σ∗ 1 is not correct since it can generate the strings “.”, “+.” and “-.”, which are not valid floating-point numbers. An NFA for L2 is r1 r2 r3 r4 r5 +, -, ε Σ1 • • Σ1 Σ1 Σ1 9
  • 10. (c) Give a regular expression for L3. Also, give an NFA for L3 over the alphabet Σ. Answer: A regular expression for L3 is R3 = (R1 ∪ R2) (E ∪ e) R1 where R1 and R2 are defined in the previous parts. An NFA for L3 is s1 s2 s3 s4 s5 s6 s7 s8 +, -, ε Σ1 • Σ1 • Σ1 Σ1 Σ1 E, e +, -, ε Σ1 Σ1 (d) Give a regular expression for the language L. Also, give an NFA for L over the alphabet Σ. Answer: Note that L = L1 ∪ L2 ∪ L3, so a regular expression for L is R4 = R1 ∪ R2 ∪ R3 We can construct an NFA for L by taking the union of the NFA’s for L1, L2 and L3, as follows: 10
  • 11. q1 q2 q3 +, -, ε Σ1 Σ1 r1 r2 r3 r4 r5 +, -, ε Σ1 • • Σ1 Σ1 Σ1 s1 s2 s3 s4 s5 s6 s7 s8 +, -, ε Σ1 • Σ1 • Σ1 Σ1 Σ1 E, e +, -, ε Σ1 Σ1 q0 ε ε ε A simpler NFA for L is to take the NFA for L3 and make s3 and s5 also accepting states in addition to s8. 11