Solution for Homework 2 Questions - Organization Program Language | CMSC 330, Assignments of Programming Languages

Material Type: Assignment; Class: ORGNZTN PROGM LANG; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-2s4
koofers-user-2s4 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 330 Homework #2– Automata Fall 2005
1. For each of the following problems construct a deterministic finite automaton which describes or recog-
nizes the language given. Write all DFAs in the form of a transition diagram. The underlying alphabet
is Σ = {a, b}.
Be sure to give a DFA for each part, and not an NFA unless the problem asks for one. Do not use any
notational conveniences or shortcuts given in lecture.
The notation #a(w) is used below to refer to the number of a’s occurring in the string w. For example,
#a(bbaba) = 2.
Note: the first seven parts are the same languages which were questions on Homework #1. It would
be very instructive to compare the DFA and the regular expression for these languages– it is suggested
that you do so.
a. {w|wbegins with abab }
b. {w|wends with abab }
c. {w|wbegins with ab and ends with ba }
Note: The string aba is in this language.
d. {w|#a(w)2 (mod 5) }
Recall that ij(mod k) if and only if ijis divisible by k.
e. {w|#a(w) is even or |w|is even }
f. {w|aaa is a substring of w}
g. {w|aaa is not a substring of w}
h. {w|wcontains exactly one occurrence of the substring aaa }
Note: the string aaaa has two occurrences of aaa.
i. {w|either #a(w) is divisible by 3 or wbegins with bbb }
Also write a regular expression which describes or recognizes this language.
j. {w|#a(w)1 (mod 3) and #b(w) is odd }
k. {w|neither aa nor bb is a substring of w}
l. Write an NFA for the language in part #1i.
2. Consider the following language:
{w|w { 0,1}and wcontains an even number of 0s, and wdoes not contain three consecutive 1s }
Determine whether each of the following DFAs correctly describes or recognizes this language or not.
Identify why each incorrect DFA is wrong– give a string which the DFA doesn’t give the right results
for, and identify what result the DFA should give for that string, and what result it actually gives.
a. dead
state
0
1
0
1
0
1
0
1
1
pf3

Partial preview of the text

Download Solution for Homework 2 Questions - Organization Program Language | CMSC 330 and more Assignments Programming Languages in PDF only on Docsity!

CMSC 330 Homework #2– Automata Fall 2005

  1. For each of the following problems construct a deterministic finite automaton which describes or recog- nizes the language given. Write all DFAs in the form of a transition diagram. The underlying alphabet is Σ = {a, b}.

Be sure to give a DFA for each part, and not an NFA unless the problem asks for one. Do not use any notational conveniences or shortcuts given in lecture.

The notation #a(w) is used below to refer to the number of a’s occurring in the string w. For example, #a(bbaba) = 2.

Note: the first seven parts are the same languages which were questions on Homework #1. It would be very instructive to compare the DFA and the regular expression for these languages– it is suggested that you do so.

a. { w | w begins with abab }

b. { w | w ends with abab }

c. { w | w begins with ab and ends with ba } Note: The string aba is in this language.

d. { w | #a(w) ≡ 2 (mod 5) } Recall that i ≡ j (mod k) if and only if i − j is divisible by k.

e. { w | #a(w) is even or |w| is even }

f. { w | aaa is a substring of w }

g. { w | aaa is not a substring of w }

h. { w | w contains exactly one occurrence of the substring aaa } Note: the string aaaa has two occurrences of aaa.

i. { w | either #a(w) is divisible by 3 or w begins with bbb } Also write a regular expression which describes or recognizes this language.

j. { w | #a(w) ≡ 1 (mod 3) and #b(w) is odd }

k. { w | neither aa nor bb is a substring of w }

l. Write an NFA for the language in part #1i.

  1. Consider the following language:

{ w | w ∈ { 0 , 1 }∗^ and w contains an even number of 0s, and w does not contain three consecutive 1s }

Determine whether each of the following DFAs correctly describes or recognizes this language or not. Identify why each incorrect DFA is wrong– give a string which the DFA doesn’t give the right results for, and identify what result the DFA should give for that string, and what result it actually gives.

a. dead state

b.

dead state

c. dead state

d. dead state

e. dead state