solutions-ass1

# solutions-ass1 - COMP 2805 Solutions Assignment 1 Question...

This preview shows pages 1–3. Sign up to view the full content.

COMP 2805 — Solutions Assignment 1 Question 1: For each of the following languages, construct a DFA that accepts the language. In all cases, the alphabet is { 0 , 1 } . (1.1) { w : w begins with 00 and contains exactly one 1 } . (1.2) { w : w begins with 00 or contains exactly one 1 } . (1.3) { ±, 101 } . Question 2: For each of the languages in the previous question, construct an NFA that accepts the language. (You cannot use the DFA’s from the previous questions.) Solution: First we do { w : w begins with 00 and contains exactly one 1 } . Any string in this language has the following form: It starts with 00. Then it has zero or more 0s. Then it has one 1. It ends with zero or more 0s. The top part of the DFA below veriﬁes whether the input string has this form. If the string has this form, the DFA ends in the rightmost state q a and, thus, accepts the string. On the other hand, as soon as a violation to the general form is seen, the DFA switches to the non-accept state q r at the bottom of the DFA and stays there forever; thus, the input string is not accepted. q q 0 q 00 q r q a q q 0 q 00 q a 0 0 0 0 1 1 1 1 0,1 0 0 0 1 0 DFA NFA The states have the following meaning: q : no symbol has been read. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
q 0 : exactly one symbol has been read and it was 0. q 00 : at least two 0’s have been read, no 1 has been read. q a : the part of the string that has been read so far belongs to the language. q
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

solutions-ass1 - COMP 2805 Solutions Assignment 1 Question...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online