0% found this document useful (0 votes)
224 views2 pages

Exercise02 PDF

This document contains an exercise sheet for a theoretical computer science course. It includes 3 exercises on regular expressions and non-deterministic finite automata (NFAs). Exercise 1 asks students to identify languages corresponding to 4 regular expressions over the alphabet {a,b,c} and provide example strings that are members and not members of each language. Exercise 2 asks students to write regular expressions for 5 languages over the alphabet {0,1}. Exercise 3 asks students to (a) draw an NFA that recognizes a language defined by a regular expression over {0-9}, and (b) provide another NFA with at most 5 states that recognizes the same language.

Uploaded by

rimsha
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)
224 views2 pages

Exercise02 PDF

This document contains an exercise sheet for a theoretical computer science course. It includes 3 exercises on regular expressions and non-deterministic finite automata (NFAs). Exercise 1 asks students to identify languages corresponding to 4 regular expressions over the alphabet {a,b,c} and provide example strings that are members and not members of each language. Exercise 2 asks students to write regular expressions for 5 languages over the alphabet {0,1}. Exercise 3 asks students to (a) draw an NFA that recognizes a language defined by a regular expression over {0-9}, and (b) provide another NFA with at most 5 states that recognizes the same language.

Uploaded by

rimsha
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/ 2

Theoretical Computer Science (Bridging Course)

Dr. G. D. Tipaldi University of Freiburg


F. Boniardi Department of Computer Science
Winter semester 2014/2015

Exercise Sheet 2
Exercise 2.1 (Regular expressions)
Consider the following regular expressions. What language do they recognize? Give two strings
that are members of the the corresponding language and two strings which are not members – a
total of four strings for each part. Assume the alphabet Σ = {a, b, c} in all parts.

(a) a∗ b∗ c∗
(b) Σ∗ abaΣ∗
∗ ∗ ∗ ∗ ∗
(c) ((a ∪ c) b(a ∪ c) b(a ∪ c) b(a ∪ c) )
(d) b ∪ (bΣ∗ b)

Solution:
(a) L = {w ∈ Σ∗ | the letters are in alphabetical order }. For example, aabb, aaaabbccc are
members, whereas acba, bbcab are not.
(b) L = {w ∈ Σ∗ | contains aba}. For example, aabc, cababac are members, whereas abc, bb are
not.
(c) L = {w ∈ Σ∗ | the number of b is a multiple of 3} For example, abbbc, bbb are members,
whereas abc, bb are not.
(d) L = {w ∈ Σ∗ | w begins and ends in b} For example, b, baaabab are members, whereas
ab, abba are not.

Exercise 2.2 (Regular Expressions)


Construct regular expressions for the following languages over the alphabet Σ = {0, 1}
(a) L1 = {w ∈ Σ∗ | every 0 in w is immediately followed by a 1}
(b) L2 = {w ∈ Σ∗ | the second or the third position from the end is a 1}

(c) L3 = {w ∈ Σ∗ | w consists of alternating 0 and 1}


(d) L4 = {w ∈ Σ∗ | w does not contain 11}
(e) L5 = {w ∈ Σ∗ | w ends in even number of 0s}

Solution:

(a) re1 = 1∗ ∪ (1∗ 011∗ )
(b) re2 = Σ∗ 1Σ ∪ Σ∗ 1ΣΣ
∗ ∗ ∗ ∗
(c) re3 = (01) ∪ (10) ∪ 0(10) ∪ 1(01)

(d) re4 = 0∗ ((100∗ ) )(1 ∪ 0∗ )
∗ ∗ ∗
(e) re5 = (1 ∪ 0) 1(00) ∪ (00)
Exercise 2.3 (NFAs and Regular Expressions)
Consider the regular expression (30∪75∪45)∗ ◦10 (over the alphabet Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}).

(a) Give the NFA that recognizes L((30 ∪ 75 ∪ 45)∗ ◦ 10). Solution:

q2 3 q3  q4 0 q5

  

q0  q1  q6 7 q7  q8 5 q9  q14 1 q15  q16 0 q17

 


q10 4 q11  q12 q13


5

(b) Give another NFA with at most 5 states that recognizes the same language (you do not have
to justify your answer).
Solution:

q1

0 3

q0 1 q3 0 q4

7, 4 5

q2

You might also like