Download Solution

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Pattern language wikipedia , lookup

Multiple-criteria decision analysis wikipedia , lookup

Computational complexity theory wikipedia , lookup

Transcript
CS 373 – Fall 2003 – NMG ****** SOLUTION ******************
September 11, 2003, updated 9/18/03 – P10 corrected
Homework Assignment 2
Due 9/19/03 (Friday) at the end of class
Problems related to chapter 2:
You are advised to study related exercises if solutions are given in the back of the book (3rd
edition). In all problems below, if an NFA is requested, the resulting NFA must have some nondeterministic element. All problems are 10 points each.
P1 Consider the “mystery” automata below. Give a reasonably simple explanation of the
language it recognizes. Simply sketching a graph for this automata is not an acceptable answer.
M = ({s, q, p, f}, {a, b}, , s, f ) where  is given by:
(s, a) = q
(s, b) = p
(q, a) = f
(q, b) = q
(p, a) = p
(p, b) = p
(f, a) = q
(f, b) = f
Answer:
The graph for this automata (not acceptable for an answer) is:
L = { (abnabm)p : n, m  0, p > 0 }, where  = {a, b}
Some students may use a regular expression: (ab*ab*)+ or some equivalent.
P2 Given the language: L = { x : x  {a, b}* : x contains the substring ababb }
(a) Design an DFA accepting this language in 6 states.
(b) Design an NFA accepting this language in the same number of states.
CS 373
Fall 2003
Problem Set 2
Page 1
(c) Which of these FA’s is more intuitive in describing this language. Explain.
Answer:
Part a (DFA):
Part b (NFA):
Part c: the NFA is more intuitive
P3 Construct a DFA accepting the language:
L = {x  {0,1}* : x represents a multiple of 7 in binary }
Assume that 0 counts as a multiple of 7, that the least significant bit is on the right, and that (as
usual) the DFA scans from left to right. Leading (left end) zeros are permitted.
Answer: Note that shifting left by 1 and “padding” on the right by 0 doubles the unshifted
number. When processing a string, the current substring just processed gets effectively shifted
left by 1 when the next symbol is consumed. The next symbol (bit) is then added to the shifted
number. Thus if n is the number corresponding the last consumed symbol, the new number
resulting after the next bit is consumed is 2n if the next bit consumed is 0, or 2n+1 if the next bit
consumed is 1. In the DFA below, the states from left to right represent: multiples of 7,
multiples of 7 + 1, multiples of 7 + 2, multiples of 7 + 3, multiples of 7 + 4, multiples of 7 + 5,
and multiples of 7 + 6 ie., 0 mod 7, 1 mod 7, and 2 mod 7, 3 mod 7, 4 mod 7, 5 mod 7, and 6
mod 7 respectively.
CS 373
Fall 2003
Problem Set 2
Page 2
m7 represents any multiple of 7 (includes 0). Labels are arbitrary except for documentation.
P4 Find a DFA accepting the language: L = {w1abw2 : w1, w2  {a, b}* }
Answer:
bbbabbb accepted
bbbabbbabaa accept ed
bbaaabbabaabb accepted
aaaa rejected
bbbaaaa rejected
P5 Let L = (w  {0,1}* : |w|  3 and the 3rd symbol from the right is 1}. Show a graph of a DFA
representing this language.
Answer:
CS 373
Fall 2003
Problem Set 2
Page 3
P6 Let  = {0, 1}. Directly design a DFA which accepts all nonempty strings on  for which the
leftmost symbol and the rightmost symbol are identical. Directly design an NFA which does the
same thing. Which solution is more intuitive – explain.
Answer:
P7 Find an NFA (graph) with three states that accepts the language:
L = {an : n  1}  {bmak : m  0, k  0 }. Re-do the problem with two states.
CS 373
Fall 2003
Problem Set 2
Page 4
Answer:
P8 Using the formal algorithm in the proof of theorem 2.2 in the text, convert the following NFA
to an equivalent DFA. The algorithm should be verified by labeling the states in the equivalent
DFA with the associated subsets or “clusters” of states from the NFA
Answer:
CS 373
Fall 2003
Problem Set 2
Page 5
P9 Construct an NFA which accepts the following language:
L = {x  {0, 1}* : the least significant bits in the string (at the right end) encodes either
the decimal numbers 5 or 10}.
Redo the problem using an DFA.
Answer:
CS 373
Fall 2003
Problem Set 2
Page 6
P10 Let  = {a, b, c }. Construct a DFA in no more than 7 states that accepts the following
language: L = { w  *: w has exactly one symbol from  missing }
Do the same using a directly constructed NFA in no more than 4 states.
Answer:
DFA:
NFA:
CS 373
Fall 2003
Problem Set 2
Page 7