Principles of Computing – UFCFA3-30-1 Week-4 Instructor : Mazhar H Malik Email : mazhar@gcet.edu.om Global College of Engineering and Technology
Extended Topics in DFA
Trap or Dead State A trap is state that, once entered, one can never leave. Used to reject partly read strings that will never be accepted, or to accept partly read strings that will definitely be accepted. Trap State: Dead states are those non final states which transits (Self Loop) in itself for all the symbol.
Set of States Q Q q0 , q1, q2 , q3, q4 , q5 Example • a,b q5 a,b
Input Alphabet • Example a,b a,b q5 a,b q4 b q0 b q3 q1 b q2 b
q0 Initial State Example a,b q5 a,b q4 b q0 b q3 q1 b q2 b
Example: • q0 , a q1 a,b q5 a,b q4 b q0 b q3 q1 b q2 b
q0 ,b q5 a,b q5 a,b q4 b q0 b q3 q1 b q2 b
state s symbols Transition Table for • b q0 q1 q5 q2 q3 q4 a,b q5
Example a,b a,b b q0 q1 Accept state q2 trap state 11
b Input String a,b a,b b q0 q1 q2 12
b a,b a,b b q0 q1 q2 13
b a,b a,b b q0 q1 q2
Input finished b a,b accept a,b b q0 q1 q2
A rejection case b Input String a,b a,b b q0 q1 q2
b a,b a,b b q0 q1 q2
b a,b a,b b q0 q1 q2
Input finished b a,b a,b b q0 q1 q2 reject
L {a nb : n 0} Language Accepted: a,b a,b b q0 q1 q2
Another Example EVEN {x : x * and x is even} Alphabet: {1} 1 q0 q1 Language Accepted: EVEN {x : x * and x is even} {, 11, 1111, 111111, }
Example 2.3 Design a DFA that accept set of strings that containing four 1’s every string over alphabet ∑ = {0,1} Solution: DFA should accepts the string 1111, 0101011, 0110110000… Let DFA be M = {Q, ∑ ,∂, q0, F}, Q = {q0, q1, q2, q4, q5}, F = {q4} Trap State: Dead states are those non final states which transits in itself for all the symbol. So q5 is example of dead state
Example 2.4 Design a DFA (Graph and Table) that accept set of strings that containing exactly 1 every string over alphabet ∑ = {0,1} Solution: DFA should accepts the string 1, 010000, 00010000… Let DFA be M = {Q, ∑ ,∂, q0, F}, Q = {q0, q1, q2, q4, q5}, F = {q1} ∂/∑ 1 -> q0 q0 q1 * q1 q2 Self Loop
Example 2.5 Design a DFA that accept Language L = {ω ∈ (0,1)* / second symbol of ω is ‘0’ and fourth input is 1} Solution: So after analyzing the problem we find that every string of the language is like 0001, 1011, 10110000… Let DFA be M = {Q, ∑ ,∂, q0, F}, Q = {q0, q1, q2, q4, q5}, F = {q4} For securing the second and fourth position we need trap state
Example 2.6 For the given DFA Write the language and also given the transition table ∂/∑ 1 -> q0 q1 q0 q2 *q2 Solution: Let the language be L for FA shown in Example 2.6 L = {ω ∈ (0,1)* /every string ω of the language containing 00 as substring}. Transition Table:
Example 2.7 Design DFA for the Language L = {(01)i 12j | i ≥ j≥1} Solution: Let analyzing the language be L for FA accept strings start with any with any number of 01 (no empty) and end with even number of 1’s Let FA be. M = {Q, ∑ ,∂, q0, F}, Q = {q0, q1, q2, q4, q5}, F = {q4}, ∑ = {0,1}
* :Q * Q * (q,w ) q Extended Transition Function Describes the resulting state after scanning string w from state q
Example: * q0,ab q2 a,b q5 a,b q4 b q0 b q3 q1 b q2 b
* q0,abbbaa q5 a,b q5 a,b q4 b q0 b q3 q1 b q2 b
q , bba * q 1 4 a,b q5 a,b q4 b q0 b q3 q1 b q2 b
Special case: for any state q * q, q
q q w * q,w q w 12 k In general: implies that there is a walk of transitions w 12 k 1 2 k q q states may be repeated w q q
Minimization of DFA’s To remove Dead State Inaccessible State Equivalent State Useless State
Step-2: ->q0 q5 q1 q2 q6 *q2 q0 q4 q7 Draw the transition table for test states, after removing q3 (unreachable state) ∂/∑ a b ->q0 q5 q1 q2 q6 *q2 q0 q4 q7
Step-3: ->q0 q5 q1 q2 q6 q4 q7 *q2 q2 q0 Now divide rows of transition table in two sets as: One set contains only those rows, which starts from non-final states i.e. Other set contains only those rows, which starts from final state Non-final states ∂/∑ a b ->q0 q5 q1 q2 q6 q4 q7 Final states ∂/∑ a b *q2 q2 q0
Step-4: Apply step-4 on both the sets individually. Now consider set-1 ∂/∑ a b Rows ->q0 q5 q1 1 q2 q6 2 q4 q7 q1 3 4 5 q7 6
Step-4: Row 2 and row 6, are similar since q1 and q7 transit to same states on a and b. So skip one of them skip skip row 6, then q7 in the rest . Write the rest as follows: ∂/∑ a b Rows ->q0 q5 q1 1 q2 q6 2 q4 3 4 5
Step-5: Repeat Step-4 on the rest set-1, till you are finding similar rows and write rest, now this set is minimized ∂/∑ a b Rows ->q0 q5 q1 1 q2 q6 2 q4 4 q7 q0 5 3
Step-5: Now minimized set is ∂/∑ a b Rows ->q0 q5 q1 1 q2 q6 2 4 q4 q0 5
Step-6: Do same process for set 2 as Final states ∂/∑ a b *q2 q2 q0
Step-7: Now combine set-1 and set-2 as ∂/∑ a b ->q0 q5 q1 q2 q6 q4 q0 *q2
Minimized DFA Transition Graph ∂/∑ a b ->q0 q5 q1 q2 q6 q4 q0 *q2
Minimized DFA - Comparison
Your Turn… Minimize the following DFA
Minimization by Transition Graph 46
Minimization Example Start with a DFA 48
Minimization Example Miniature version 49
Sources http://www.jflap.org/tutorial/ www1.cs.solumbia.edu/~zeph/3261/L9/L9.ppt Theory of computation by A. Pandey http://www.cburch.com/proj/autosim/