COMP1600 COMP6260 代写 ANU

The Australian National University School of Computing
Dirk Pattinson and
Semester 2, 2021 Practical Session 8
– S0 – S3 􏰍3􏰇􏰆
Foundations of Computation
The practical contains a number of exercises designed for the students to practice the course content. During the practical session, the tutor will work through some of these exercises while students will be responsible for completing the remaining exercises in their own time. There is no expectation that all the exercises will be covered in the practical session.
Covers: Lecture Material Week 8
At the end of this tutorial, you will be able to
• minimise FSAs;
• construct Non-Deterministic Finite Automata from (ε-) Non-Deterministic Finite Automata;
• build Regular Expressions given a language;
• construct an equivalent Deterministic Finite Automaton from a Non-Deterministic Finite Automaton; • construct an equivalent (ε) Non-Deterministic Finite Automaton from a Regular Expression.
Exercise 1 NFA to DFA conversion
1. Construct a non-deterministic finite state automaton that accepts the language of binary strings that begin and end with the same bit. Try to use as few states as you can. (Note that strings that are one letter long satisfy this predicate, and so should be accepted).
2. Use the subset construction algorithm to construct an equivalent deterministic FSA from your previous answer. Solution.
The following table demonstrate implementation of subset construction algorithm. The state labelled with → is the initial state while the states denoted with ⊙ are the final states.
→S0 S13 S23 ⊙S13 S13 S1 ⊙S23 S2 S23 S1 S13 S1 S2 1S2 S23
Exercise 2
Regular Expressions
Consider the alphabet Σ = {a, b}. Build Regular Expressions for:
1. the set of strings over Σ∗ that consists of alternating a’s and b’s;
(ε | a)(ba)∗(ε | b)
2. the set of strings over Σ∗ that contains an even number of a’s and b’s;
(aa | bb | (ab | ba)(aa | bb)∗(ab | ba))∗
Exercise 3 Identifying Equivalent States
Consider the DFA given by the following state diagram:
S2 a S4 a,b Identify all equivalent states of this automation using the algorithm given in the lectures.
Solution. To simplify notation, we just write 1 for S1 and similarly for all other states.
1. The initial partition just distinguishes final states and non-final states. That is, we start with [[1, 5], [2, 3, 4]].
2. We test [2,3,4] for splitting. Since 2 −→ 1 and 3 −→ 4 and 1 and 4 are (by the previous step) known to be non-equivalent, they need to be in different partitions.
Similarly, 4 −→ 4 and 3 −→ 5 and 4 and 5 are (by the previous step) non-equivalent, they need to be in different paritions.
This means that we separate all states in [2, 3, 4] in the next partition and obtain [[1, 5], [2], [3], [4]] as the second
partition.
2. Convert the automaton to an NFA using the algorithm given in the lectures.
3. We now test [1, 5] for splitting. We have 1 −→ 3 and 5 −→ 3 so they produce equivalet states on a. Moreover, bb
4. As the singletion sets [2], [3] and [4] cannot be split, no more splittings are possible, and [[1, 5], [2], [3], [4]] is the final partition.
That is, only states S1 and S5 are equivalent in the above automation. Exercise 4 From ε-NFAs to NFAs
Consider the ε-NFA given by the following state diagram: aεa
1 −→ 2 and 5 −→ 2 so they also produce equivalent (even identical) states on b. That means that we don’t need to split [1, 5].
1. Compute the ε−closure of each state. Solution.
• eclose(S0) = {S0}
• eclose(S1) = {S1, S0}
• eclose(S2)={S2,S1,S0}
a a a,b S b S
Alternatively, you can follow the algorithm from the videos. It would yield the following NFA:
Exercise 5
From Regular Expressions to ε-NFAs
For the regular expression 00(0 | 1)∗
• use the algorithm given in lectures to produce a ε-NFA A
a,b,c start S0
• describe the language that A accepts. Phrase your answer in the form L(A) = {w ∈ Σ∗ | P (w)}, where P (w) is some predicate on words.
L(A) = {w ∈ {0, 1}∗ | w contains all binary numbers starting with 00} A=
εε S0S0SεS SεS
0123εεε45 S1S
Exercise 6
Consider the non-deterministic finite automaton A: 􏰌􏰉
􏰍3 􏰇 􏰆 0 􏰍􏰋􏰊
U 􏰈 􏰁􏰂0,1 􏰋􏰊
1. Describe the language that this automaton accepts.
Solution. The language L(A) is the set of all binary integers that are even (or, equivalently, end in 0), but without
unnecessary leading 0s.
2. Use the subset construction algorithm to construct an equivalent deterministic FSA from your previous answer.
Solution. The following table demonstrate implementation of subset construction algorithm. State labelled with → is the initial state while the states denoted with ⊙ are the final states.
→Ss ⊙ST SU
Exercise 7 More Regular Expressions
Consider the alphabet Σ = {a, b}. Build Regular Expressions for:
1. the set of strings over Σ∗ that contains an odd number of a’s;
(b | ab∗a)∗ab∗
2. the set of strings over Σ∗ that ends with b and does not contains the substring aa;
(b | ab)∗(b | ab)
3. the set of string over Σ∗ that contains a number of a’s that is a multiple of 3.
b∗ | (b∗ab∗ab∗ab∗)∗
Exercise 8 More from ε-NFAs to NFAs Consider the ε-NFA given by the following state diagram:
ST SU S∅ S∅
SUT SU S∅ S∅
Here, we have started the construction with the initial state, SS , and have only added states to the transition table
that are in fact reachable from the initial state.
1. Compute the ε−closure of each state. Solution.
• eclose(S0)={S0,S1,S2} • eclose(S1) = {S1}
• eclose(S2) = {S2}
2. Convert the automaton to an NFA using the algorithm given in the lectures.
Alternatively, you can follow the algorithm from the videos. It would yield the following NFA:
Exercise 9
From Regular Expressions to ε-NFAs
For each of the following regular expressions
• use the algorithm given in lectures to produce a ε-NFA A
• describe the language that A accepts. Phrase your answer in the form L(A) = {w ∈ Σ∗ | P (w)}, where P (w) is some predicate on words.
Solution. L(A) = {w ∈ {0, 1}∗ | w begins with 0 followed by 1’s} A=
start S 0 S ε S 1 S ε S
2. (0 | 1)01; Solution.
L(A) = {w ∈ {0, 1}∗ | w is the 3-bit binary representation of either 1 or 5} A=
S 0 S 1 S 0 567