meljun cortes - automata with solution and answer
TRANSCRIPT
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
1/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
SET
It is any well defined collection of objects.
It is a collection of distinct objects, without repetition and without ordering. It is denoted by capital letter.
Example:A = { , ,0} C = {1, 2, 3}B = {a, b, c, d} D = {Len, Joseph}
1. Roster / Tabular Form
Listing or enumerating all the elements of a given set.
Example: A = {a, b, c}
2. Set-Builder Form Elements have properties in common.
Elements must satisfy a given rule or condition.Example: A = {x | x is a positive integer < 4}
A = {x | x < 5}
It is a member of a given set or an object in the collection.
It is denoted by small letter/s.Example:
A = {a, b, c} ; a A; b A; c A; d A
1. elements can be counted.
Example:A = {a, b, c}
2. elements cannot be counted.
Example:A = {x | x is a positive integer}
1. Order of elements is not important2. Repetition must be ignored
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
2/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
If A is a subset of B, A is contained in B or every element of A is in B.
Example:A = {a, b}
B = {a, b, c}
Every set is a subset of itself.
An empty set is a subset of every set.
If A B then there is at least one element in A that is not in B.
Example: Let A = {1, 2, 3}
= {{1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}, {}}
To check:|A| = 2n = 8
A is a proper subset of B if A B and A B
It is the total number of elements in a given set
Example:A = {1, 2, 3}
|A| = 3
It is a set containing no element
Example : A = { } or A = {}
A = {} is not an empty set
It is a set containing only one element.e.g. A = {1}
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
3/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
At least one set is a subset of another set.
Conditions so that A & B are comparable:
1. A B & B A
Example: A = {1, 2, 3, 4}B = {4, 3, 2, 1}
2. A B & B A
Example: A = {1, 2}B = {1, 2, 3}
3. A B & B AExample: A = {a, b, c}
B = {a, b}
No set is a subset of the other set. (A B & B A & A B)
Example: A = {l, e, n}B = {s, e, p, h}
Sets having exactly the same cardinality and kind of elements.
Example: A = {l, e, n}B = {n, l, e}
Set having the same cardinality.
Example: A = {1, 2, 3}B = {4, 5, 6}
Every element of A is associated or paired to every element in B.
Example: A = {1, 2, 3}B= {l, e, n}
Sets having no common elements
Example A = {1, 4, 5}B = {3, 2, 6}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
4/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
It is the biggest set under investigation wherein the other sets are subsets of this givenset.
Example: Let U= {1, 2, 3, 4, 5, 6}A = 1, 2, 3}B = {4, 5, 6}C = {5, 6}
It is a collection of set. All elements of the given set are sets.
Example: A = {A, B, C}A = {{1, 2, 3}, {4, 5, 6}, {5, 6}}
B = {A, B, C, D, 0, 2}C = {A, B, C, D, z}
new set of elements that belong to U but not in A (with respect to U)
Example: Let U= {1, 2, 3, 4, 5, 6}
A = {1, 2, 3}A = {4, 5, 6}
new set of elements that belong to B but not in A (with respect to B)
Example: Let B = {a, b, c, d, e}
A = {a, b, c}A = {d, e}
It is a family of all subsets of a given set.
It is the set of all subsets.
Example: Let A = {1, 2, 3}P (A) = {{1}, {2}, {3}, {1, 2}, {1, 3}, {}, {1, 2, 3}}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
5/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
1.
It is a new set of elements that belong to A or to B or to both A and B.
Example: Let A = {1, 2, 3, 4}B = {2, 4, 6, 7}
AB = {1, 2, 3, 4, 5, 6, 7}
2.
It is a new sets of elements that belong to both A and B.
Example: Let A = {1, 2, 3, 4}B = {2, 4, 6, 7}
AB = {2, 4}
3.
It is a new set of elements that belong to A but not to B.
Example: Let A = {1, 2, 3, 4, 5}
B = {1, 2, 4, 6, 7}A - B = {3, 5}B - A = {6, 7}
4.
It is a new set of elements that belongs to U but not to A.
Example: Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9}A = {1, 2, 3, 4}B = {2, 4, 6}
A = {5, 6, 7, 8, 9}
B = {1, 3, 5, 7, 8, 9}
5. It is a new set of elements that belong to A or B but not to A and B.
Example: Let A = {1, 2, 3, 4, 5}B = {0, 1, 2, 6, 7, 8}
A B = {0, 3, 4, 5, 6, 7, 8}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
6/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
It deals with idealized computer device.
It tells how to design and use special language.
3.
It tells whether the problem is algorithmically solvable or not.
It tells how to design and use special language.
It is a finite set of symbols.
It can be letters from a to z or digits from 0-9.
It is denoted by .
It is a finite sequence of an alphabet.
It is a set of strings generated from some alphabets.
Examples:
Let {a,b}
Write the strings generated from the given sets.
1. L1 = A set of strings that begins and ends with .
Answer:
L1 ={aa, aba, abbbba, aaaaa, aaaaba, }
2. L2 = A set of strings divisible by 2.
Answer:
L2 ={aa, bb, abba, bbaa, bababa, }
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
7/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
It is any number of leading symbols of a string.
Example: W ={star}Prefix of a String = {e, s, st, sta, star}
It is any number of leading symbols other than the string itself.
Example: W ={star}Proper Prefix of a String = {e, s, st, sta}
It is any number of trailing symbols of a string.
Example: W ={star}Suffix of a String = {e, r, ar, tar, star }
It is any number of trailing symbols other than the string itself.
Example: W ={star}
Proper Suffix of a String = {e, r, ar, tar}
It is string formed by writing the first string followed by the second string with nointervening spaces.
It is denoted by ( ) concatenation operator.
Example:
automata theory = automatatheory
* That is if w & x are strings, then wx is the concatenation of these two strings.
It is denoted by WR.
It is a string that spelled backwards.
Example:marilynR = nyliram
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
8/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez
2003
It is a mathematical model of a system with discrete inputs and outputs.
It consist of finite set of a sets and a set of transitions from state to state the occur on
input symbol chosen from alphabet ().
1. states qs and ps
2. q0 initial state
3. 0, 1, a, b input symbols
4. w, x, y, z strings of input symbols.
Finite Automata
are limited in strength but they are a thoroughly understood subclass of more powerfulcomputational models.
a further reason for studying FA is their applicability to the design of several common types ofcomputer algorithms and programs.
Example:Lexical analysis phase of Compilers is often based on the simulation of a automatation.
Vertices denotes the store
Edges transition function
Initial State Final State
( set of states, set of input alphabet )
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
9/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
Example:State Diagram
qo q1
State Table
x y
q0 q1 q1q1 q0 q0
Transition Function
(q0,x) = q0
(q0,y) = q0
(q1,x) = q1
(q1,y) = q1
1. For each input symbol in , there is exactly one transition of each state (possibly back to
the state itself).
It do not accept empty strings.
It is a quintuple where M = (Q, , q0, , F)
where:Q = finite set of all sets
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
10/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
= finite set of input symbolsq0 = initial state
= transition functionF = set of final state
Prepared by: Marilyn M. Sanchez2003
Examples:
1. Diagrams that ends with 10.
qo
q1 q21
0 1
0
1
0
Transition Table
x y
q0 q1 q1
q1 q2 q1q2 q3 q1
Strings that can be derived:
10
010
0110
01010
Transition Function
(q0,0) = q0
(q0,1) = q1
(q1,0) = q2 (q1,1) = q1
(q2,0) = q0
(q2,1) = q1
2. Draw a transition diagram that will end with 001.
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
11/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
qo
q1 q30
1 0
0q2
1
01
1
Prepared by: Marilyn M. Sanchez2003
* In FA or DFA, for each input there is exactly one transition output of each state.
Lets try to modify the finite automaton by alowing zero, one or more transitions from astate on the same input symbol. The modified model is called Non-Deterministic FiniteAutomaton.
If for some ofQ, a, (q,a) does either to a unique state or several states or notstates at all, then the FA is a NFA.
A Non-Deterministic Finite Automaton is a quintuple M=(Q,,q0,,F)
where: Q = set of states
= set of input alphabets
= transition function
---> QX to 2Qq0 = initial stateF = set of final state
It allows zero, one or more transitions for every inputs symbol.
Empty string accepted
A sequence of symbols, say a1, a2, ...an is accepted by NFA if there exists a sequence of
transition corresponding to the input sequence that leads from the initial states to thefinal state.
Example:Construct a NFA that accepts string ending with 011.
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
12/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
qo
q1 q30
1
1q2
1
0
(q0,011)--> q3To check if 1011 is a valid string
q0q0q1q2q2
q0q0q0
Prepared by: Marilyn M. Sanchez2003
The reason for the word nondeterministic is that we are in a state where there aremultiple outgoing edges all having the same input symbol we have a choice of next state.
The only difference between a NFA & DFA is that in DFA the next state function takesus to a uniquely defined state whereas in NFA the next state takes us to a set of states.
Example :
qo
q1
q4
01
0
q2
q3
q2
q00
1
1
1,0
0
1
0 1
q0 {q0,q3} {q0,q1}
q1 0 {q2}
q2 {q2} {q2}
q3 {q4} 0
q4 {q4} {q4}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
13/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Let the input be 01001
(q0, ) =
(q0, 0) = ((q0, )0) = (q0,0)=
(q1, 01) = ((q0,0)1) =(q0,1) U (q3,1)={q0,q1}U{ }=
(q1, 010) = ((q0,01)0)=(q0,0) U (q1,0)={q0,q3}U{ }=
(q2, 0100) = ((q0,010)0)=(q0,1) U (q3,1) U (q3,0)={q0,q3} U
{q4}=
(q2, 01001) = ((q0,1) U (q3,1) U (q4,1) = {q0,q1} U {} U {q4}=
Prepared by: Marilyn M. Sanchez2003
Theorem: For every NFA model, there exist one and only one equivalent DFA
Let M be the equivalent DFA of a NFA M.
M=(Q, ,,q0,F)
Example:Transform the given NFA to DFA
qo
q20
q11
000,1
={{},q0,q1,q2,{q0,q1},{q0,q1},{q0,q2},{q1,q2},{q0,q1,q2}}
=q2 ={q2,{q0,q2},{q1,q2},{q0,q1,q2}}
0 1
q0 {q0} {q0,q1}
q1 {q1,q2} {}
q2 {q2} {}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
14/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
({},0) = {}
({},1) = {}
(q0,0) = q0
(q0,1) = {q0,q1}
(q1,0) = {q1,q2} (q1,1) = {}
(q2,0) = q2
(q2,1) = {}
((q0,q1),0) = {q0,0} U (q1,0)
= q0 U {q1,q2} = {q0,q1,q2}
((q0,q1),1) = {q0,1) U (q1,1)
= {q0,q1} U {} = { q0,q1}
((q0,q2),0) = {q0,0) U (q2,0)= {q0} U {q2} = {q0,q2}
Prepared by: Marilyn M. Sanchez2003
((q0,q2),1) = {q0,1) U (q2,1)= {q0,q1} U {q2} = {q0,q1,q2}
((q1,q2),0) = {q1,0) U (q2,0)
= {q1,q2} U {q2} = {q1,q2} ((q0,q1,q2),0) = {q0,0) U (q1,0) U (q2,0)
= {q0} U {q1,q2} U {q2} = {q0,q1,q2}
((q0,q1,q2),1) = {q0,1) U (q1,1) U (q2,1)
= {q0,q1} U {} U {} = {q0,q1}
0 1
q0 {q0} {q0,q1}
q1 {q1,q2} {}
q2 {q2} {}q0,q1 {q0,q1,q2} {q0,q1}
q0,q2 {q0,q2} {q0,q1}
q1,q2 {q1,q2} {}
q0,q1,q2 {q0,q1,q2} {q0,q1}
{} {} {}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
15/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
{}
q1
q2
q1q2
10
0
0
1
1
0,1
Prepared by: Marilyn M. Sanchez2003
It is quintuple M = {Q,,,q0,F} where the transition functions maps.
:Q x ( U {})2Q
(q,a)={p | (q,a) p and a= or a
will consist of all states p such that there is a transition labeled a from q to p where a is
either or a symbol in the.
-closure(q)= { p | , a path from q to p marked }-closure(p)= Uqp -closure where p is a set of states
: Q x 2Q
(q,w) { p | (q,w) contains p including edges labeled (q,) = -closure (q)
* (q,w) will be all states p such that one can go from q to p doing a path labeled w,perhaps including edges labeled .
Example:
q0q0,q1
q0,q1,q2
q0,q2
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
16/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
qo
q3
q1 a
a
q2
transition: (q0,a) q0
(q0,) q1
(q1,) q2
(q2,a) q3
-closure:
q0
q0 q1
q0 q1 q2
Prepared by: Marilyn M. Sanchez2003
For each NFAs there is one and only one equivalent NFA.
NFA or NFAs: M = {Q, , , q0, F}
Let Equivalent NFA be M = {Q, , 1, q0, F1}
where: F = {F U closure (qo)1 l closure (qo) contains state of F }
Example:
1. Convert the given NFA to NFA.
qo
q3
q1
0
q2
1 2
-closure (q0) = {q0,q1,q2}-closure (q1) = {q1,q2}-closure(p) = -closure of {q0,q1}
= -closure {q0} U -closure {q1}= {q0,q1,q2} U {q1,q2}= {q0,q1,q2}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
17/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
0 1 2 q0 {q0} {} {} q1
q1 {} q1 {} q2
q2 {} {} q2 {}
0 1 2
q0 {q0,q1,q2} {q1,q2} {q2}
q1 0 {q1,q2} {q2}
q2 {} {} {q2}
= {F U closure (q0)}= {q0,q1,q2}
qo
q3q1
0
q2
1 2
0,1,2
0,11,2
Prepared by: Marilyn M. Sanchez2003
2. Convert the given NFA to NFA.
q0
q4 q5
q1 q2 q2q3
q5
a,b
a a
a,b
b
b
F = {q3,q5} -closure (q0) = {q0,q1,q4}q0 = {q0}
= {a,b}
a b E
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
18/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
q0 {} {} {q1,q4}
q1 {q1,q2} q1 {}
q2 {q3} {} {}
q3 {q3} {q3} {}
q4 {} {q4} {}
q5 {} {q5} {}
a b
q0 {q1,q2} {q1,q5}
q1 {q1,q2} {q1}
q2 {q3} 0
q3 {q3} {q3}
q4 {} {q5}
q5 {} {q5}
Prepared by: Marilyn M. Sanchez2003
F = {q3,q5}
q0
q4
q5
q1
q2 q2q3
q5
a,b
a
a
a,b
b
b
b
a,b
a
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
19/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Prepared by: Marilyn M. Sanchez2003
DEFINITION: is an alphabet
A regular expression over is recursively defined as:
1. 0 is a regular expression denoting the set of {}.
2. is a regular expression denoting the set of {}.
3. For any a , a is a regular expression denoting the set {a}.4. If r,s,t are reg. exp. Denoting sets R,S,T respectively, then
(r t s) denotes R u S
rs denotes RSr* denotes R*
finite set of symbols
L1,L2,L: set of strings from
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
20/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Examples:
a. L1L2 = { xyl xL1 ^ YL2} is the concatenation of L1 & L2e.g = {a,b}
L1 = {a,b} {}={}
L2 = {ba,a} ={}
L1L2 = {a} {ba}{b} {a }
= {aba,aa,bba,ba}
b. L0 = {}Li = LL i1
e.g. L = {0,1}
L0 = {}
Find L3
L1 = LL0 = {0,1},{}= {0,1}
L2 = LL1 ={0,1}{0,1}
= {00,01,10,11}L3 = LL2 = {0,1}{00,01,10,11}
= {000,001,010,011,100,101,110,111}
Prepared by: Marilyn M. Sanchez2003
of L is defined asL* = U
Li
i = 0
of L is defined asL+ = U
Li
i = 0
Example:L = {0,1}L* = {e,0,1,00,11,101,01,10,111,000,101,..}L+ = {0,1,00,11,101,01,10,111,000,101,.}
L = {1}L* = {e,1,11,111,1111,..}
Examples: Let = {0,1}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
21/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
1. 0 = {0}
2. 01 = {01}
3. 0 + 1 = {0,1}
4. 1* = {e,1,11,111,1111,}5. 0* + 1 = {e,0,1,00,000,..}
6. 1*00 = {00,100,1100,11100,.}7. (0+1)* = {e,0,1,00,11,000,111,10,01,101,0001.}8. (00+1*)* = {e,00,1,11,1111,00001,100.}9. (010+101) = {e,010,101,1011,10111,101111..}
10. (0+1)*101 = set of strings ending with 101.11. (0+1)*11(0+1)* = set of strings with 11 as a substring.
REGULAR EXRESSION NFA
0 or {}qo q1
= {}* w/o inputqoq0
a = {a}q
oq
1a
Prepared by: Marilyn M. Sanchez2003
If r & s are regular expression, assume that there is a NFAe corresponding to r &
s.
q0 qf L (r) q0 qf L (s)
a. r + s ( r or s)
q0 q2qf
q0 qf L (r)
q0 qf L (s)
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
22/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
b. rs (r concatenates s or concatenation of rs)
q0 qf L (s)q0 qf L (r)
c. r* (r closure or r kleene closure)
q0 q2qf
q0 qf L (r)
Examples:
Construct the equivalent NFAe of the ff, reg. expression:
1. 0 W/ ANSWER na ni..
qo
q1
0
Prepared by: Marilyn M. Sanchez
2003
2. 01
q2qo
q11
q3
0
3. 0+1
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
23/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
q2
qo
q1
1q4q3
q5
0
4. 1*
q2q
oq1
1q3
5. 11+0
q1
1
0
0q7
q2
q2q5
0
q2q
oq1 q3
111
1q3q1 q2 q4
1
q6
q0
Prepared by: Marilyn M. Sanchez2003
Context-free Grammars describe context-free languages.
Regular set is an example of Context Free language.
Context-Free grammar (CFG) is a quadruple
G = (V,T,P,S) where V set of variables {S,B}
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
24/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
T set of terminals (a,b,c)
P Production or rule (How to form the string)S the starting symbol
Examples :
Construct CFG for the following:
1. ab*c = {ac,abc,abbc,abbbc,.}
given: S aBc
B bB
B
S aBc S aBc S aBc
ac abBc abbBc
ac abc abbbBc
abc abbbbBc
abbbbbBc
abbbbbc
abbbbbc
2. Construct a CFG for anbn; n>0
= {ab,aabb,aaabbb..}V=SS=ST={a,b}
P: S aSb
S
S aSb S aSb ab aaSbb
ab aabb
aabb
Prepared by: Marilyn M. Sanchez2003
3. Construct a CFG for the following: W/ ANSWER na ni..a. 0*1 = {1,01,001,..}
V=S,B
T={0,1}S=S
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
25/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
P: S B1
B0B
B
S B1 S B1
1 0B1 1 00B1
000B1
0001
0001b. (0+1)*
S 1s|0s
S
01 111001
S 0s S 1s
01s 11s
01
111s 01 1110s
11100s
111001s
111001
111001
c. ambn | m>= n
S aMb
M aMb | aM |
aabb aaabb
S aMb S aMb
aaMbb aaMbb aabb aaaMbb
aabb aaabb
aaabb
Prepared by: Marilyn M. Sanchez2003
d. S | 0 | 1
S 1s1 | 0s0
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
26/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
S 0s0 S 1s1 S 0s0
00 101 00s00
00 00100
e. zanzbnz | n>=0
S aSb S aSb
ab aaSbb
ab aabb
aabb
f. set of integers (+ or -)
S +N| -N
S 0N | | 9N | 0 | | 9
S +N S -N
+1N -9N
+10 -98N
-987
g. {anbncmdm | n,m > 0}
S abcd| aMbcNd
M aMb |
N aNb |
aabbcd aabbccdd
S aMbcNd S aMbcNd
aaMbbcd aaMbbccNdd aabbcd aabbccdd
aabbcd aabbccdd
Prepared by: Marilyn M. Sanchez2003
S MN
M aMb |ab
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
27/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
N cNd | cd
aabbcd
S MN
aMbcd
aabbcd
h. {xmyxm| m >= 0} S xSx |y
S xSx S xSx
xyx xxSxx
xxxSxxx
xxxyxxx
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
28/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Context Free Grammars machine counterpart.(Just as the RE have an equivalent
autometon-FA).
Non deterministic device.(Deterministic version is only a subset of all CFLs).
Have input tape, finite control and a stack
Essentially a FA with control of both input and stack FILO list.
is a string of symbols from some alphabet. The leftmost symbol of the stack isconsidered to be the tape of the stack.
1. An input symbol is used.
Depending on the input symbol, the top symbol on the stack, and state of thefinite control, a number of choices are possible. Each choice consist of next statefor the finite control and a (possibly empty) string of symbols to replace the topstack symbol. After selecting a choice, the input head is advanced one symbol.
2. Input symbol is not used (-move).
Similar to the first except that the input symbol is not used and the input head isnot advanced after the move.
Allows the PDA to manipulate the stack without reading input symbols.
no final state empty both input
tape & stack
1. Set of all inputs for which some sequence of moves causes the PDA to empty a stack.2. Designate some states as final sates define the accepted language as the set of all inputs
for which some choice of moves causes the PDA to enter final state.
with final state empty input tape
M = (Q, , , , qo, Zo, F)
where:
Q = finite set of all sets = finite set of input symbols = stack alphabet
q0 = in Q, initial state
Zo = in , start symbol
F = Q, set of final states
= mapping Q x ( U {}) x to Q x *
(q, a, Z) = {(P1, y1)(Pm, ym)}initial state Pop Push
Input Destination State
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
29/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Example:
M = ( {q1,q2}, {0,1}, {R, B, G}, , q1, R, q2 )
1. ( q1, 0, R ) = {( q1, BR )}
2. ( q1, 1, R ) = {( q1, GR )}
3. ( q1, 0, B ) = {( q1, BB )}, {( q2, )}
4. ( q1, 0, G ) = {( q1, BG )}
5. ( q1, 1, B ) = {( q1, GB )}
6. ( q1, 1, G ) = {( q1, GG )}, {( q2, )}
7. ( q2, 0, B ) = {( q2, )}
8. ( q2, 1, G ) = {( q2, )}
9. ( q1, , R ) = {( q2, )}
10. ( q2, , R ) = {( q2, )}
Determine if the input 001100 is valid for PUSHDOWN AUTOMATA.
(q1,001100,R)
(q1,01100,BR) (q2,001100,)
(q1,1100,BBR) (q2,1100,R) (q2,1100,)
(q1,100,GBBR) (q1,0,BGGBBR)
(q1,00,GGBBR) (q2,00,BBR)
(q1,0,BGGBBR) ( q2, 0,BR ) ( q2, , R ) ( q2, , )
(q1,,BBGGBBR) (q2,,GGBBR)
? ?
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
30/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
M = (Q, , , , qo, B, F)where:
Q = finite set of all sets
= finite set of allowable tape symbolsB = in , is blank
= not includingB, set of input symbols
q0 = in Q, start stateZo = in , start symbol
F = Q, set of final states
= next move function Q x to Q x {L,R}
initial state destination head movement
state
(basic model) has finite control, input tape that is divided into cells, a tape head thatscans one cell of the tape at a time.
Introduced by Allan Turing in 1936
Tape has a leftmost cell but infinite to the right
Each cell may hold exactly one of a finite number of tape symbols
Initially, the n leftmost cell (n>0) hold the input, which is a string of symbolschosen from a subset of the tape symbols called input symbols.
The remaining infinity of cells each hold blank, which is a special tape symbolthat is not input symbol.
Finite Control
In one move, the TM (depending upon the symbol scanned by th tape head & the state of finitecontrol)
1. changes state2. prints symbol on the tape cell scanned, replacing what was written there3. moves its head left or right one cell
Prepared by: Marilyn M. Sanchez2003
a1 a2 a1 an B B
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
31/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
Recursively enumerable strings can be enumerated or listed by a Turing
Machine.Example:
M = ({qo, q1 q4}, {0,1}, {0,1,x,y,B}, , q0, B, q4)
qo (q1,x,R) (q3,y,R)
q1 (q1,0,R) (q2,y,L) (q1,y,R)
q2 (q2,0,L) (q0,x,R) (q2,y,L)
q3 (q3,y,R) (q4,B,R)
q4
Determine if the given inputs are accepted by TM
1. 0011
State Head Position
qo 0011q1 x011q1 x011q2 x0y1q2 x0y1
qo x0y1
q1 xxy1q1 xxy1q2 xxyyq2 xxyyqo xxyy
q3 xxyyq3 xxyyBq4 xxyyBB
Therefore, accepted
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
32/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
2. 0011
State Head Position
qo 0011 01q1 x01101
q1 x01101q2 x0y101q2 x0y101qo x0y101q1 xxy101q1 xxy101
q2 xxyy01
q2 xxyy01qo xxyy01q3 xxyy01q3 xxyy01
?Therefore, not accepted
Prepared by: Marilyn M. Sanchez2003
-
7/31/2019 MELJUN CORTES - AUTOMATA with SOLUTION and ANSWER
33/33
MELJUN P. CORTES--------> Theory of Automata and Formal Language
2012
AMA COMPUTER UNIVERSITYProject 8, Quezon City
COLLEGE OF COMPUTER STUDIES
MANUALINAUTOMATA THEORY
Prepared by :MELJUN P. CORTES
MSCS STUDENT