0% found this document useful (0 votes)
124 views8 pages

SOLUTIONS: Homework Assignment 2: CSCI 2670 Introduction To Theory of Computing, Fall 2018 September 18, 2018

This document provides the questions and solutions for Homework Assignment 2 of an introduction to theory of computing course. The homework covers topics including NFAs, converting NFAs to DFAs, operations on regular languages, and regular expressions. There are 8 questions requiring students to design NFAs and DFAs, provide regular expressions, and identify positive and negative examples of language members. Figures and detailed steps are included in the solutions.

Uploaded by

Orijit Nandy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views8 pages

SOLUTIONS: Homework Assignment 2: CSCI 2670 Introduction To Theory of Computing, Fall 2018 September 18, 2018

This document provides the questions and solutions for Homework Assignment 2 of an introduction to theory of computing course. The homework covers topics including NFAs, converting NFAs to DFAs, operations on regular languages, and regular expressions. There are 8 questions requiring students to design NFAs and DFAs, provide regular expressions, and identify positive and negative examples of language members. Figures and detailed steps are included in the solutions.

Uploaded by

Orijit Nandy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SOLUTIONS: Homework Assignment 2

CSCI 2670 Introduction to Theory of Computing, Fall 2018

September 18, 2018

This homework assignment is about NFA, NFA to DFA conversion, opera-


tions on regular languages, and regular expressions

1. Design an NFA to recognize the following language, where Σ = {a, b, c}

L1 = {w : the second last symbol of w is not ‘a’ }

Answer:

Figure 1: NFA for L1 (credited: Connor Dooley)

1
2. Design an NFA to recognize the following language, where Σ = {a, b, c}

L2 = {w : w contains an even number of a’s or contains the pattern ’aa’}

Answer:

Figure 2: NFA for L2 (credited: Connor Dooley)


3. Based on the work for Questions 1 and 2, design an NFA to recognize each of the
following languages:
(a) L1 ∪ L2 ;
(b) L1 L2 ;
(c) L∗1 ;
Answer:
(a)

Figure 3: NFA for L1 ∪ L2 (credited: Connor Dooley)

(b)

Figure 4: NFA for L1 L2 (credited: Connor Dooley)


(c)

Figure 5: NFA for L∗1 (credited: Connor Dooley)


4. Consider the following NFA. Convert it to an equivalent DFA using the studied
method. Note the simple conversion process is to construct the extension set E after
related transitions are determined. For example, if R is a subset of states in the NFA
that has transition function δ, then for symbol x, the new transition function ∆(R, x)
is computed as the result of the following sequence of steps:

Figure 6: state diagram of an NFA

(1) compute δ(r, x) for every r ∈ R;


(2) compute extension set E(δ(r, x)) for every r ∈ R, if relevant -transitions exist;
S
(3) take the union r∈R E(δ(r, x));
Draw the final DFA converted from the NFA.
Answer:
You would like to show all steps in computing the new transition function ∆(R, x) for
every R and every x. Showing these steps serve two purposes:
(a) to reward you with partial credits even if your final answer may be wrong, and
(b) to remind you how you have come to the final answer.

(1) There are 8 possible states in the new DFA:

∅, {q0 }, {q1 }, {q2 }, {q0 , q1 }, {q0 , q2 }, {q1 , q2 }, {q0 , q1 , q2 }

(2) The new transition ∆ is defined as:


∆({q0 }, a) = {q0 , q1 }, ∆({q0 }, b) = ∅
∆({q0 , q1 }, a) = {q0 , q1 }, ∆({q0 , q1 }, b) = {q0 , q1 , q2 }
∆({q0 , q1 , q2 }, a) = {q0 , q1 }, ∆({q0 , q1 , q2 }, b) = {q0 , q1 , q2 }
(3) The start state is {q0 , q1 };
(4) The accept states are {q0 , q1 } and {q0 , q1 , q2 }.
Figure 7: Converted DFA

5. For each of the following regular expressions, give two positive and two negative
members for the language it generates:
(a) a(ba)∗ b;
(b) ( ∪ b)a;
Answers:
(a)
positive members: ab, abababab
negative members: aba, 
(b)
positive members: a, ba
negative members: ab, bb
6. Design an NFA for each of language given in Question 5.
Answers
(a)

Figure 8: NFA for a(ba)∗ b (credited: Connor Dooley)

(b)

Figure 9: NFA for ( ∪ b)a (credited: Connor Dooley)

7. Give regular expressions for the following languages, where Σ = {0, 1}


(a) {w : w contains exactly two 0’s }
(b) {w : w contains at least two 0’s and at most one 1 }
Hints: There are only a few ways that “exactly two 0’s” can be arranged
in a string. “At least two 0’s” is the same as ”exactly two 0’s or more than
two 0’s”.
answers:
(a) 1∗ 01∗ 01∗
(b) 000∗ ∪ 1000∗ ∪ 0100∗ ∪ 000∗ 10∗
8. In certain programming languages, comments appear between delimiters such as /#
and #/. Let C be the language of all valid delimited comment strings. Such a string
in C must begin with /# and end with #/ but have no intervening #/. For simplicity,
assume the alphabet Σ = {a, b, /, #}.
(a) Give an NFA that recognizes language C.
(b) Give a regular expression that generates C.
Answers:
(a)

Figure 10: NFA that recognizes language C

(b) /#(a ∪ b ∪ / ∪ (#∗ (a ∪ b)))∗ #/

NOTE: All homework answers need to be word-processed or typed. Hand-writing only


applies to figure or table drawings. A hard copy of answers should be received in classroom
or in the instructor’s office by 5:00pm on the due date. Policy on late homework answers
is given in the syllabus. Email submission will not be accepted unless a such a request has
been approved.

You might also like