cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska
LECTURE 6a
REVIEW for Q2 Q2 covers Lecture 5 and Lecture 6 Chapter 2 - Deterministic Finite Automata DFA Chapter 2 - Nondeterministic Finite Automata NDFA 1. Some YES- NO Questions 2. Some Very Short Questions 3. Some Homework Problems
CHAPTER 2 PART 1 Deterministic Finite Automata DFA Nondeterministic Finite Automata NDFA
Short YES/NO Questions Here are solutions to some short YES/NO Questions for material covered in Chapter 2, Part 1 Solving Quizzes and Tests you have to write a short solutions and circle the answer You will get 0 pts if you only circle your answer without providing a solution, even if it is correct Here are some questions Q1 Alphabet Σ of any deterministic finite automaton M is always non-empty no An alphabet Σ is, by definition, any finite set, hence it can be empty Q2 The set K of states of any deterministic finite automaton is always non-empty yes s K
Short YES/NO Questions Q3 A configuration of a DF Automaton M = (K, Σ, δ, s, F) is any element of K Σ K no Configuration is any element (q, w) K Σ Q4 Given an automaton M = (K, Σ, δ, s, F), a binary relation M (K Σ ) (K Σ ) is a transition relation iff he following condition holds (q, aw) M (q, w) iff δ(q, a) = q no Proper condition is: (q, aw) M (q, w) iff δ(q, a) = q Q5 A configuration of a non- deterministic finite automaton M = (K, Σ,, s, F) is any element of K Σ yes by definition
Short YES/NO Questions Q6 Given M = (K, Σ, δ, s, F) we define L(M) = {w Σ : ((s, w) M(q, e)) for some q K} no Must be: for some q F Q7 Given M = (K, Σ, δ, s, F) we define L(M) = {w Σ : q K ((s, w) M(q, e))} no Must be: q F ((s, w) M(q, e)) Observe that Q7 is really the Q6 written in symbolic way correctly using the symbol of existential quantifier
Short YES/NO Questions Q8 If M = (K, Σ, δ, s, F) is a deterministic, then M is also non-deterministic yes The function δ is a (special) relation on K Σ K, i.e. δ K Σ K K Σ {e} K K Σ K Q9 no For any automata M, we have that L(M) Take M with Σ = or F = then we get L(M) = Q10 For any DFA M = (K, Σ, δ, s, F), e L(M) if and only if s F yes this is the DFA Theorem
Short YES/NO Questions Q11 M = (K, Σ,, s, F) is non-deterministic when K Σ K no we must say: is finite Q12 M = (K, Σ,, s, F) is non-deterministic when K (Σ {e}) K yes this is book definition; do not need to say is a finite set, as the set K (Σ {e}) K is always finite Q13 The set of all configurations of any non-deterministic state automata is always non-empty yes the set of all configuration of NDFA is by definition K Σ = {(q, w) : q K, w Σ } and we have that (s, e) K Σ even when Σ = as always s K, e Σ
Short YES/NO Questions Q14 We say that two automata M 1, M 2 (deterministic or nondeterministic) are the same, i.e. M 1 = M 2 if and only if L(M 1 ) = L(M 2 ) no we say that M 1, M 2 are equivalent, i.e. M 1 M 2 if and only if L(M 1 ) = L(M 2 ) Q15 For any DFA M, there is is a NDFA M M yes This is the Equivalency Theorems 1 M, such that Q16 For any NDFA M, there is is a DFA M, such that M M yes This is the Equivalency Theorems 2
Short YES/NO Questions Q17 If M = (K, Σ,, s, F) is a non-deterministic as defined in the book, then M is also non-deterministic, as defined in the lecture yes Σ {e} Σ Q18 We define, for any (deterministic or non-deterministic M = (K, Σ,, s, F) a computation of the length n from (q, w) to (q, w ) as a sequence (q 1, w 1 ), (q 2, w 2 ),..., (q n, w n ), n 1 of configurations, such that q 1 = q, q n = q, w 1 = w, w n = w and (q i, w i ) M(q i+1, w i+1 ) for i = 1, 2,..n 1 Statement: For any M a computation (q, w) exists yes By definition a computation of length one (case n=1) always exists
Very Short Questions For all short questions given on Quizzes and Tests you will have to do the following 1. Decide and explain whether the diagram represents a DFA, NDFA or does not 2. List all components of M when it represents DFA, NDFA 3. Describe L(M) as a regular expression when it represents DFA, NDFA
Very Short Questions Consider a diagram M1 1. Yes, it represents a DFA; δ is a function on {q 0, q 1 } {a} and initial state s = q 0 exists 2. K = {q 0, q 1 }, Σ = {a}, s = q 0, F = {q 1 }, δ(q 0, a) = q 1, δ(q 1, a) = q 1 3. L(M1) = aa
Very Short Questions Consider a diagram M2 1. Yes, it represents a DFA; δ is a function on {q 0 } {a} and initial state s = q 0 exists 2. K = {q 0 }, Σ = {a}, s = q 0, F =, δ(q 0, a) = q 0 3. L(M2) =
Very Short Questions Consider a diagram M3 1. Yes, it represents a DFA; initial state s = q 0 exists 2. K = {q 0 }, Σ =, s = q 0, F =, δ = 3. L(M3) =
Very Short Questions Consider a diagram M4 1. Yes, it represents a DFA; initial state s = q 0 exists 2. K = {q 0 }, Σ = {a}, s = q 0, F = {q 0 }, δ(q 0, a) = q 0 3. L(M4) = a Remark e L(M4) by DFA Theorem, as s = q 0 F = {q 0 }
Very Short Questions Consider a diagram M5 1. NO! it is NOT neither DFA nor NDFA - initial state does not exist
Very Short Questions Consider a diagram M6 1. It is not a DFA; Initial state does exist, but δ is not a function; δ(q 0, b) is not defined and we didn t say plus trap states 2. It is a NDFA 3. L(M6) =
Consider a diagram M7 Very Short Questions 1. Yes! it is a DFA with trap states Initial state exists and we can complete definition of δ by adding a trap state as pictured below
Very Short Questions Consider again diagram M7 2. If we do not say plus trap states it represents a NDFA with = {(q 0, a, q 1 ), (q 1, a, q 1 ), (q 1, b, q 1 )} 3. L(M7) = as F =
Very Short Questions There is much more Short Questions examples in the section SHORT PROBLEMS at the end of Lecture 5
Some Homework Problems Problem 1 Construct deterministic M such that L(M) = {w Σ : w has an odd number of a s and an even number of of b s } Solution Here is the short diagram - we must say: plus trap states
Some Homework Problems Problem 2 Construct a DFA M such that L(M) = {w {a, b} : every substring of length 4 in word w contains at least one b } Solution Here is a short pattern diagram (the trap states are not included)
Some Homework Problems Problem 3 Construct a DFA M such that L(M) = {w {a, b} : every word w contains an even number of sub-strings ba } Solution Here is a pattern diagram Zero is an even number so we must have that e L(M), i.e. we have to make the initial state also a final state
Some Homework Problems Problem 4 Construct a DFA M such that L(M) = {w {a, b} : w has abab as a substring } Solution The essential part of the diagram must produce abab and it can be surrounded by proper elements on both sides and can be repeated Here is the essential part of the diagram
Problem 4 Solutions We complete the essential part following the fact that it can be surrounded by proper elements on both sides and can be repeated Here is the diagram of M Observe that this is a pattern diagram; you need to add names of states only if you want to list all components M does not have trap states
Some Homework Problems Problem 5 Use book or lecture definition (specify which are you using) to construct a non-deterministic finite automaton M, such that L(M) = (ab) (ba) Specify all components K, Σ,, s, F diagram of M and draw a state Justify your construction by listing some strings accepted by the state diagram
Problem 5 Solutions Solution 1 We use the lecture definition Components of M are: Σ = {a, b}, K = {q 0, q 1 }, s = q 0, F = {q 0, q 1 } We define as follows = {(q 0, ab, q 0 ), (q 0, e, q 1 ), (q 1, ba, q 1 )} Strings accepted: ab, abab, abba, babba, ababbaba,...
Problem 5 Solutions Solution 2 We use the book definition Components of M are: Σ = {a, b}, K = {q 0, q 1, q 2, q 3 }, s = q 0, F = {q 2 } We define as follows = {(q 0, a, q 1 ), (q 1, b, q 0 ), (q 0, e, q 2 ), q 2, b, q 3 ), (q 3, a, q 2 )} Strings accepted: ab, abab, abba, babba, ababbaba,...
Some Homework Problems Problem 6 Let M = (K, Σ, s,, F ) for K = {q 0, q 1, q 2, q 3, }, s = q 0, Σ = {a, b, c}, F = {q 3 } and = {(q 0, abc, q 0 ), (q 0, ab, q 1 ), (q 1, bb, q 3 ), (q 0, b, q 2 ), (q 2, aa, q 3 )} Find the regular expression describing the L(M). Simplify it as much as you can. Explain your steps Solution L(M) = (abc) abbb abbb (abc) baa ba = (abc) abbb (abc) baa(abc) (abbb baa) We used the property: LL 1 LL2 = L(L 1 L 2 )
Some Homework Problems Problem 7 Let M = (K, Σ, s,, F ) for K = {q 0, q 1, q 2, q 3, }, s = q 0, Σ = {a, b, c}, F = {q 3 } and = {(q 0, abc, q 0 ), (q 0, ab, q 1 ), (q 1, bb, q 3 ), (q 0, b, q 2 ), (q 2, aa, q 3 )} Write down (you can draw the diagram) an automaton M such that M M and M is defined by the BOOK definition. Solution We apply the stretching technique to M and the new M is is as follows. M = (K {p 1, p 2,..., p 5 } Σ, s = q 0,, F = F ) = {(q 0, b, q 2 ), (q 0, a, p 1 ), (p 1, b, p 2 ), (p 2, c, q 0 ), (q 0, a, p 3 ), (p 3, b, q 1 ), (q 1, b, p 4 ), (p 4, b, q 3 ), (q 0, b, q 2 ), (q 2, a, p 5 ), (p 5, a, q 3 )}
Some Homework Problems I will NOT include this problem on Q2, but you have to know how to solve similar problems for Midterm Problem 8 Let M be defined as follows M = (K, Σ, s,, F ) for K = {q 0, q 1, q 2 }, s = q 0, Σ = {a, b}, F = {q 0, q 2 } and = {(q 0, a, q 1 ), (q 1, b, q 2 ), (q 1, b, q 0 ), (q 2, a, q 0 )} Write 4 steps of the general method of transformation a NDFA M, into an equivalent M, which is a DFA
Problem 8 Reminder E(q) = {p K : (q, e) M(p, e)} and δ(q, σ) = {E(p) : q Q (q, σ, p) } p K Step 1 Evaluate δ(e(q 0 ), a) and δ(e(q 0 ), b) Step i+1] Evaluate δ on all states that result from Step i
Problem 8 Solution δ(q, σ) = {E(p) : q Q (q, σ, p) } p K Step 1 E(q 0 ) = {q 0 }, E(q 1 ) = {q 1 }, E(q 2 ) = {q 2 } δ({q 0 }, a) = E(q 1 ) = {q 1 }, δ({q 0 }, b) = } Step 2 δ(, a) =, δ(, a) =, δ({q 1 }, a) =, δ({q 1 }, b) = E(q 0 ) E(q 2 ) = {q 0, q 2 } F
Problem 8 Solution δ(q, σ) = {E(p) : q Q (q, σ, p) } Step 3 p K δ({q 0, q 2 }, a) = E(q 1 ) E(q 0 ) = {q 0, q 1 }, δ({q 0, q 2 }, b) = Step 4 δ({q 0, q 1 }, a) = E(q 1 ) = {q 1 }, δ({q 0, q 1 }, b) = E(q 0 ) E(q 2 ) = {q 0, q 2 } F