Download presentation
Presentation is loading. Please wait.
Published byMyron Moore Modified over 9 years ago
1
Deterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.2)
2
State-driven programs Many applications carry out actions only when particular conditions apply at the given moment conditions => state Examples: Buying items online: a payment can be made only after checkout Performing a simple arithmetic calculation using a calculator: an operator character should be pressed only after some sequence of digits have been entered for the first operand
3
Model: finite automaton At any point in time, the “program” or automaton will be in one state from a set of states In the calculator example, the states are: reading the first operand first operand read (+ or - is pressed) reading the second operand result displayed/ready for next calculation (= is pressed) A transition from one state to another state occurs on a given input symbol
4
Accepting valid calculator input We want the automaton to allow (accept) input strings like this 123+456= 3333-5= But “reject” string like this +-2=2 567-= Symbols are read from left to right and cause transitions from one state to another based on the current state and current input symbol
5
Deterministic Finite Automata A DFA or deterministic finite automaton M is a 5-tuple, M = (Q, , , q 0, F), where: Q is a finite set of states of M is the finite input alphabet of M : Q Q is the state transition function q 0 is the start state of M F Q is the set of accepting states or final states of M
6
DFA example 1 State diagram Q = { q 0, q 1 } = { 0, 1 } F = { q 1 } q0q0 q1q1 0 1 0 1M 01 q0q0 q0q0 q1q1 q1q1 q1q1 q0q0 State Table
7
State table & state transition function State table State transition function (q 0, 0) = q 0, (q 0, 1) = q 1 (q 1, 0) = q 1, (q 1, 1) = q 0 01 q0q0 q0q0 q1q1 q1q1 q1q1 q0q0
8
A DFA processing a string Given a string of input symbols w = a 1 a 2 … a n A DFA M processes the string w as follows: Start with state q x = q 0 For each input symbol a i : q x = (q x, a i ) If resulting q x F, then w is accepted; otherwise w is rejected
9
Extending for strings Let w be a string over and let M = (Q, , , q 0, F) be a DFA Define ^: Q X * Q as follows If w = , then ^(q, w) = ^(q, ) = q If w ≠ , i.e., w = xa, (where x is a string and a is a symbol) then ^(q, w) = ^(q, xa) = ( ^(q, x), a) A DFA M accepts a string w when ^(q 0, w) F
10
Language recognized by a DFA The language L(M) that is recognized by a DFA M = (Q, , , q 0, F), is the set of all strings accepted by M. That is, L(M) = { w * | M accepts w } = { w * | ^(q 0, w) F } Example: For the previous DFA, L(M) is the set of all strings of 0s and 1s with odd parity, that is, odd number of 1s.
11
DFA Example 2 Recognizer for 11*01* B D A C 1 1 0 1 0 0 0,1 Trap * means zero or more occurrences of the preceding symbol
12
DFA Example 2 M = (Q, , , q 0, F), L(M) = 11*01* Q = { q 0 =A, B, C, D } = { 0, 1 } F = { C } 01 ADB BCB CDC DDD
13
DFA Example 3 Modulo 3 counter A B C 1 1 1 2 2 2 0 0 0
14
DFA Example 3 M = (Q, , , q 0, F) Q = { q 0 =A, B, C } = { 0, 1, 2 } F = { A } 012 AABC BBCA CCAB
15
DFA Example 4 Recognizing simple calculator expressions M = (Q, , , q 0, F) Q = { q 0 =ready, readingop1, op1read, readingop2 } = { 0…9, +, -, = } F = { ready } See course website for a sample Java program that simulates this DFA (study how the transition function is implemented)
16
Regular Languages and DFAs A language L * is called regular if there exists a DFA M such that L(M)=L Examples of regular languages Binary strings with odd parity Language described by 11*01* Strings that form integers divisible by 3 Simple calculator expressions
17
Next Variations on Finite Automata (rest of Chapter 2) Nondeterministic Finite Automata (NFAs) Equivalences of these variations with DFAs Regular expressions as an alternative model for regular languages (Chapter 3)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.