1. Modeling Computation - 12 CSC1001 Discrete Mathematics 1
CHAPTER
การคํานวณตามแบบจําลอง
12 (Modeling Computation)
1 Finite-State Machines
1. Finite-State Machines with Output
Definition 1
A finite-state machine M = (S,I,O, f, g, s0) consists of a finite set S of states, a finite input alphabet I, a finite
output alphabet O, a transition function f that assigns to each state and input pair a new state, an output
function g that assigns to each state and input pair an output, and an initial state s0.
Show the table of finite-state machine for a vending machine (State table)
Show the directed graph of finite-state machine for a vending machine (State diagram)
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
2. 2 CSC1001 Discrete Mathematics 12 - Modeling Computation
Example 1 (5 points) Construct the state diagram for the finite-state machine with the state table.
Example 2 (5 points) Construct the state diagram for the finite-state machine with the state table.
Example 3 (5 points) Construct the state diagram for the finite-state machine with the state table.
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
3. Modeling Computation - 12 CSC1001 Discrete Mathematics 3
Example 4 (5 points) Construct the state table for the finite-state machine with the state diagram.
Example 5 (5 points) Construct the state table for the finite-state machine with the state diagram.
Example 6 (5 points) Construct the state table for the finite-state machine with the state diagram.
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
4. 4 CSC1001 Discrete Mathematics 12 - Modeling Computation
2. Finite-State Machines with No Output
Definition 2
A finite-state automaton M = (S, I, f, s0, F) consists of a finite set S of states, a finite input alphabet I, a
transition function f that assigns a next state to every pair of state and input (so that f : S × I S), an initial
or start state s0, and a subset F of S consisting of final (or accepting states).
Example 7 (5 points) Construct the state diagram for the finite-state automaton M = (S, I, f, s0, F), where S =
{s0, s1, s2, s3}, I = {0, 1}, F = {s0, s3}, and the transition function f is given in Table.
Answer
Example 8 (5 points) Construct deterministic finite-state automata that recognize each of these languages.
(This is the solutions of an example)
1) The set of bit strings that begin with two 0s
2) The set of bit strings that contain two consecutive 0s
3) The set of bit strings that do not contain two consecutive 0s
4) The set of bit strings that end with two 0s
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
5. Modeling Computation - 12 CSC1001 Discrete Mathematics 5
5) The set of bit strings that contain at least two 0s
Example 9 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit strings
beginning with 01.
Example 10 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit strings
that end with 10.
Example 11 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit strings
that contain the string 101.
Example 12 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit strings
that do not contain three consecutive 0s.
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
6. 6 CSC1001 Discrete Mathematics 12 - Modeling Computation
2 Finite-State Machines
1. Regular Expressions
Definition 1
The regular expressions over a set I are defined recursively by:
the symbol ∅ is a regular expression;
the symbol λ is a regular expression;
the symbol x is a regular expression whenever x ∈ I ;
the symbols (AB), (A ∪ B), and A* are regular expressions whenever A and B are regular expressions.
Each regular expression represents a set specified by these rules:
∅ represents the empty set, that is, the set with no strings;
λ represents the set {λ}, which is the set containing the empty string;
x represents the set {x} containing the string with one symbol x;
(AB) represents the concatenation of the sets represented by A and by B;
(A ∪ B) represents the union of the sets represented by A and by B;
A* represents the Kleene closure of the set represented by A.
Example of regular expression
Example 13 (11 points) Describe in words the strings in each of these regular sets.
1) 1*0
2) 1*00*
3) 111 ∪ 001
4) (1 ∪ 00)*
5) (00*1)*
6) (0 ∪ 1)(0 ∪ 1)*00
7) 001*
8) (01)*
9) 01 ∪ 001*
10) 0(11 ∪ 0)*
11) (101*)*
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
7. Modeling Computation - 12 CSC1001 Discrete Mathematics 7
Example 14 (8 points) Determine whether 0101 belongs to each of these regular sets.
1) 01*0*
2) 0(11) * (01) *
3) 0(10)*1*
4) 0*10(0 ∪ 1)
5) (01)*(11)*
6) 0*(10 ∪ 11)*
7) 0*(10)*11
8) 01(01 ∪ 0)1*
Example 15 (8 points) Determine whether 1011 belongs to each of these regular sets.
1) 10*1*
2) 0*(10 ∪ 11)*
3) 1(01)*1*
4) 1*01(0 ∪ 1)
5) (10)*(11)*
6) 1(00)*(11)*
7) (10)*1011
8) (1 ∪ 00)(01 ∪ 0)1*
Example 16 (10 points) Express each of these sets using a regular expression.
1) The set consisting of the strings 0, 11, and 010
2) The set of strings of three 0s followed by two or more 0s
3) The set of strings of odd length
4) The set of strings that contain exactly one 1
5) The set of strings ending in 1 and not containing 000
6) The set containing all strings with zero, one, or two bits
7) The set of strings of two 0s, followed by zero or more 1s, and ending with a 0
8) The set of strings with every 1 followed by two 0s
9) The set of strings ending in 00 and not containing 11
10) The set of strings containing an even number of 1s
มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี