Discrete-Chapter 12 Modeling Computation

976 views
807 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
976
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Discrete-Chapter 12 Modeling Computation

  1. 1. Modeling Computation - 12 CSC1001 Discrete Mathematics 1 CHAPTER การคํานวณตามแบบจําลอง 12 (Modeling Computation) 1 Finite-State Machines1. 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. 2 CSC1001 Discrete Mathematics 12 - Modeling ComputationExample 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. 3. Modeling Computation - 12 CSC1001 Discrete Mathematics 3Example 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. 4 CSC1001 Discrete Mathematics 12 - Modeling Computation2. 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. AnswerExample 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 0s2) The set of bit strings that contain two consecutive 0s3) The set of bit strings that do not contain two consecutive 0s4) The set of bit strings that end with two 0sมหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
  5. 5. Modeling Computation - 12 CSC1001 Discrete Mathematics 55) The set of bit strings that contain at least two 0sExample 9 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit stringsbeginning with 01.Example 10 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit stringsthat end with 10.Example 11 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit stringsthat contain the string 101.Example 12 (5 points) Construct a deterministic finite-state automaton that recognizes the set of all bit stringsthat do not contain three consecutive 0s.มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
  6. 6. 6 CSC1001 Discrete Mathematics 12 - Modeling Computation 2 Finite-State Machines1. 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 expressionExample 13 (11 points) Describe in words the strings in each of these regular sets.1) 1*02) 1*00*3) 111 ∪ 0014) (1 ∪ 00)*5) (00*1)*6) (0 ∪ 1)(0 ∪ 1)*007) 001*8) (01)*9) 01 ∪ 001*10) 0(11 ∪ 0)*11) (101*)*มหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี
  7. 7. Modeling Computation - 12 CSC1001 Discrete Mathematics 7Example 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)*118) 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)*10118) (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 0102) The set of strings of three 0s followed by two or more 0s3) The set of strings of odd length4) The set of strings that contain exactly one 15) The set of strings ending in 1 and not containing 0006) The set containing all strings with zero, one, or two bits7) The set of strings of two 0s, followed by zero or more 1s, and ending with a 08) The set of strings with every 1 followed by two 0s9) The set of strings ending in 00 and not containing 1110) The set of strings containing an even number of 1sมหาวิทยาลัยราชภัฏสวนส ุนันทา (ภาคการศึกษาที่ 2/2555) เรียบเรียงโดย อ.วงศ์ยศ เกิดศรี

×