You are on page 1of 33

MELJUN P.

CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AUTOMATA THEORY PAGE 1
SET
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}
Methods i n Descri bi ng a Set:
1. Li sti ng Method – Roster / Tabular Form
= Listing or enumerating all the elements of a given set.
Example: A = {a, b, c}
2. Rul e Method – 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}
El ement
= 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
Types of Set
1. Fi ni te – elements can be counted.
Example:
A = {a, b, c}
2. Infi ni te – elements cannot be counted.
Example:
A = {x | x is a positive integer}
Thi ngs to remember i n l i sti ng el ements:
1. Order of elements is not important
2. Repetition must be ignored
Prepared by: Marilyn M. Sanchez
2003
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AUTOMATA THEORY-Sets PAGE 2
Subset ( ⊆ )
= 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}
A ⊆ B but B ⊄ A
Note:
- 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}
Subsets of A are:
P (A) = {{1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}, {}}
To check:
|A| = 2
n
= 8
Proper Subset ( ⊂ or ⊆ )
= A is a proper subset of B if A ⊆ B and A ≠ B
Cardi nal i ty of the set (| |)
= It is the total number of elements in a given set
Example:
A = {1, 2, 3}
|A| = 3
Empty Set / Nul l or Voi d Set
= It is a set containing no element
Example : A = { } or A = {ϕ}
A = {ϕ} is not an empty set
Si ngl eton
= It is a set containing only one element.
e.g. A = {1}
Prepared by: Marilyn M. Sanchez
2003
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AUTOMATA THEORY-Sets PAGE 3
Comparabl e set
= 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 ⊆ A
Example: A = {a, b, c}
B = {a, b}
Non-Comparabl e Set
= 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}
Equal Set
= Sets having exactly the same cardinality and kind of elements.
Example: A = {l, e, n}
B = {n, l, e}

Equi val ent Set
= Set having the same cardinality.
Example: A = {1, 2, 3}
B = {4, 5, 6}
One-to-One Correspondence
= Every element of A is associated or paired to every element in B.
Example: A = {1, 2, 3}
B= {l, e, n}
Di sj oi nt Set
= Sets having no common elements
Example A = {1, 4, 5}
B = {3, 2, 6}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Sets PAGE 4
Uni versal Set (set of al l sets)
= It is the biggest set under investigation wherein the other sets are subsets of this given
set.
Example: Let U = {1, 2, 3, 4, 5, 6} *NO REPETITION
A = 1, 2, 3}
B = {4, 5, 6}
C = {5, 6}
Sets of Sets, Fami l y of Sets, Cl ass of Sets
= 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}
A Compl ement wi th Respect to: A, A

, A
C
U = 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}
B = 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}
Power Set (P (A))
= 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}}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Sets PAGE 5
BASIC OPERATIONS
1. Uni on ( A∪B )
= 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}
A∪B = {1, 2, 3, 4, 5, 6, 7}
2. Intersecti on (A∩B)
= 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}
A∩B = {2, 4}
3. Di fference ( A – B, A / B, A ∼ B)
= 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. Compl ement (A’ ,A
C
, A , A compl ement)
= 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. Symmetri cal Di fference (A ⊕ B)
= 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}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 6
STRINGS, ALPHABETS AND LANGUAGE
The Theory of Computati ons
1. Automata Theory
= It deals with idealized computer device.
2. Theory on Formal Language
= It tells how to design and use special language.
3. Theory of Computabi l i ty
= It tells whether the problem is algorithmically solvable or not.
Al phabet
= 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 Σ.
Stri ng Reference
= It is a finite sequence of an alphabet.
Language
It is a set of strings generated from some alphabets.
Examples:
Let Σ = {a,b} ÷ Al phabet
Write the strings generated from the given sets.
1. L1 = A set of strings that begins and ends with a. ÷ Stri ng Reference
Answer:
L1 ={aa, aba, abbbba, aaaaa, aaaaba, ……… } ÷ Language
2. L2 = A set of strings divisible by 2.
Answer:
L2 ={aa, bb, abba, bbaa, bababa, ……… }
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Stri ngs, Al phabets and Language PAGE 7
Prefi x of a Stri ng
= It is any number of leading symbols of a string.
Example: W ={star}
Prefix of a String = {e, s, st, sta, star}
Proper Prefi x of a Stri ng
= It is any number of leading symbols other than the string itself.
Example: W ={star}
Proper Prefix of a String = {e, s, st, sta}
Suffi x of a Stri ng
= It is any number of trailing symbols of a string.
Example: W ={star}
Suffix of a String = {e, r, ar, tar, star }
Proper Suffi x of a Stri ng
= It is any number of trailing symbols other than the string itself.
Example: W ={star}
Proper Suffix of a String = {e, r, ar, tar}
Concatenati on of Two (2) Stri ngs
= It is string formed by writing the first string followed by the second string with no
intervening 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.
Reversal Of Stri ngs W
= It is denoted by W
R
.
= It is a string that spelled backwards.
Example:
marilyn
R
= nyliram
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 8
FINITE AUTOMATA
Fi ni te Automata
= 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 (Σ).
CONVENTIONS:
1. states ¬ q’s and p’s
2. q0 ¬ initial state
3. 0, 1, a, b ¬ input symbols
4. w, x, y, z ¬ strings of input symbols.
NOTE:
Finite Automata
= are limited in strength but they are a thoroughly understood subclass of more powerful
computational models.
= a further reason for studying FA is their applicability to the design of several common types of
computer algorithms and programs.
Example:
Lexical analysis phase of Compilers is often based on the simulation of a automatation.
Three (3) Ways Of Presenti ng Fi ni te Automata
1. State Di agram (DIAGRAM)
Vertices ¬ denotes the store
Edges ¬ transition function

Initial State Final State


2. State Tabl e
3. Transi ti on Functi on
δ ( set of states, set of input alphabet )
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Fi ni te Automata PAGE 9
Example:
State Diagram
q
o
q
1
State Table
x y
q0 q1 q1
q1 q0 q0
Transition Function
δ (q0,x) = q0
δ (q0,y) = q0
δ (q1,x) = q1
δ (q1,y) = q1
Two Types Of Fi ni te Automata :
1. Determi ni sti c Fi ni te Automata (DFA)
= 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
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Σ = finite set of input symbols
q0 = initial state
δ = transition function
F = set of final state
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Fi ni te Automata PAGE 10
Transi ti on Di agram
Examples:
1. Diagrams that ends with 10.
q
o
q1 q2
1
0 1
0
1
0
Transition Table
x y
q0 q1 q1
q1 q2 q1
q2 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.
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
q
o
q1 q3
0
1 0
0
q2
1
0
1
1
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Fi ni te Automata PAGE 11
2. Non Determi ni sti c Fi ni te Automata (NFA)
*RECALL: In FA or DFA, for each input there is exactly one transition output of each state.
Let’s try to modify the finite automaton by alowing zero, one or more transitions from a
state on the same input symbol. The modified model is called Non-Deterministic Finite
Automaton.
If for some of ∈Q, a∈Σ, δ (q,a) does either to a unique state or several states or not
states 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 2Q
q0 = initial state
F = 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 the
final state.
Example:
Construct a NFA that accepts string ending with 011.
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
q
o
q1 q3
0
1
1
q2
1
0
δ(q0,011)--> q3
To check if 1011 is a valid string
q0¬q0¬q1¬q2¬q2 val i d
q0¬q0¬q0 not val i d

Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Non Determi ni sti c Fi ni te Automata(NFA) PAGE 12
* The reason for the word “nondeterministic” is that we are in a state where there are
multiple 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 takes
us to a uniquely defined state whereas in NFA the next state takes us to a set of states.
Example : NFA Di agram
q
o
q1
q4
0 1
0
q2
q3
q2
q0
0
1
1
1,0
0
1
State Tabl e
0 1
q0 {q0,q3} {q0,q1}
q1 0 {q2}
q2 {q2} {q2}
q3 {q4} 0
q4 {q4} {q4}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Transi ti on Functi on
Let the input be 01001
δ (q0, ∈) = q0
δ (q0, ∈0) = δ(δ(q0, ∈)0) = δ(q0,0)={q0,q3}
δ (q1, ∈01) = δ(δ(q0,0)1) =δ(q0,1) U δ(q3,1)={q0,q1}U{ }={q0,q1}
δ (q1, ∈010) = δ(δ(q0,01)0)=δ(q0,0) U δ(q1,0)={q0,q3}U{ }
={q0,q3}
δ (q2, ∈0100) = δ(δ(q0,010)0)=δ(q0,1) U δ(q3,1) U δ(q3,0)={q0,q3} U
δ {q4}={q0,q3,q4}
δ (q2, ∈01001) = δ(δ(q0,1) U δ(q3,1) U δ(q4,1) = {q0,q1} U {} U {q4}
= {q0,q1,q4}
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 13
EQUIVALENCE of DFA and NFA
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

q
o
q2
0
q1
1
0
0
0, 1
Q’ ={{},q0,q1,q2,{q0,q1},{q0,q1},{q0,q2},{q1,q2},{q0,q1,q2}}
F =q2
F’ ={q2,{q0,q2},{q1,q2},{q0,q1,q2}}
Transi ti on Tabl e of NFA
0 1
q0 {q0} {q0,q1}
q1 {q1,q2} {}
q2 {q2} {}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012

Transi ti on Functi on
δ’ ({},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. Sanchez
2003
AUTOMATA THEORY- Equi val ence of DFA and NFA PAGE 14
δ’ ((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}
State Tabl e Of DFA
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}
{} {} {}
Transi ti on Di agram Of DFA
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012

{}
q1
q2
q1q2
1
0
0
0
1
1
0,1
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 15
NON-DETERMINISTIC FINITE AUTOMATION WITH Є-
MOVES
= It is quintuple M = {Q,Σ,δ,q0,F} where the transition functions δ maps.
δ:Q x (Σ U {Є}) ¬ 2
Q
δ(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)= UqЄp Є-closure where p is a set of states
δ : Q x Σ∗ →2
Q

δ (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:
q0
q0,
q1
q0,q
1,q2
q0,
q2
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
q
o
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. Sanchez
2003
AUTOMATA THEORY PAGE 16
EQUIVALENT NFA of NFA
Є
Theorem: For each NFA’s there is one and only one equivalent NFA.
NFA or NFA’s: 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.
q
o
q3
Є
q1
Є
0
q2
1 2
NFAЄ
Є-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}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
0 1 2
ε
q0 {q0} {} {} q1
q1 {} q1 {} q2
q2 {} {} q2 {}
NFA
0 1 2
q0 {q0,q1,q2} {q1,q2} {q2}
q1 0 {q1,q2} {q2}
q2 {} {} {q2}
F’ = {F U Є–closure (q0)}
F’ = {q0,q1,q2}
Transformed NFA
q
o
q3 q1
0
q2
1 2
0,1,2
0,1
1,2
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY- Equi val ent NFA of NFAЄ PAGE 17
2. Convert the given NFAε to NFA.
q0
q4 q5
q1 q2 q2 q3
q5
a,b
a
a
a,b
b
b
Є
Є
F = {q3,q5} Є-closure (q0) = {q0,q1,q4}
q0 = {q0}
Σ = {a,b}
NFAЄ
a b E
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

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} {}
NFA
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. Sanchez
2003
AUTOMATA THEORY- Equi val ent NFA of NFAЄ PAGE 18
F’ = {q3,q5}
q0
q4
q5
q1
q2 q2 q3
q5
a,b
a
a
a,b
b
b
b
a,b
a
Transformed NFA
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 19
REGULAR EXPRESSIONS
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 RS
r* denotes R*
Σ finite set of symbols
L1,L2,L: set of strings from Σ
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
Examples:
a. L1L2 = { xyl xЄL1 ^ YЄL2} is the concatenation of L1 & L2
e.g Σ = {a,b}
L1 = {a,b} {Є}={}
L2 = {ba,a} Є ={}
L1L2 = {a} {ba}
{b} {a }
= {aba,aa,bba,ba}
b. L
0
= {Є}
L
i
= LL
i–1
e.g. L = {0,1}
L
0
= {Є}
Find L3
L
1
= LL
0
= {0,1},{Є}
= {0,1}
L
2
= LL
1
={0,1}{0,1}
= {00,01,10,11}
L
3
= LL
2
= {0,1}{00,01,10,11}
= {000,001,010,011,100,101,110,111}
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Regul ar Expressi ons PAGE 20
• KLEENE CLOSURE of L is defined as
L* = U
α
L
i
i = 0
• POSITIVE CLOSURE of L is defined as
L+ = U
α
L
i
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}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

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 {}
q
o
q
1
Є = {Є}* w/o input
q
o
q0
a = {a}
q
o
q
1
a
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Regul ar Expressi ons PAGE 21
+ 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 q2 qf
q0 qf L (r)
q0 qf L (s)
Є
Є
Є
Є
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

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 q2 qf
Є
q0 qf L (r)
Є
Є
Є
Examples:
Construct the equivalent NFAe of the ff, reg. expression:
1. 0 W/ ANSWER na ni…..
q
o
q
1
0
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Regul ar Expressi ons PAGE 22
2. 01
q2 q
o
q1
1
q3
0
Є
3. 0+1
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
q2
q
o
q1
1
q4 q3
q5
0
Є
Є
Є
Є
4. 1*
Є
Є
Є
q2 q
o
q1
1
q3
Є
5. 11+0
q1
1
0
0
q7
q2
q2 q5
0
Є
q2 q
o
q1 q3
1 11
1
Є
q3 q1 q2 q4
1
q6
q0
Є
Є Є
Є
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 23
CONTEXT-FREE GRAMMARS
= 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}
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

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 ¬Є
ac abc abbbbbc
S ¬aBc S ¬aBc S ¬aBc
¬aЄc ¬abBc ¬abbBc
¬ac ¬abЄc ¬abbbBc
¬abc ¬abbbbBc
¬abbbbbBc
¬abbbbbЄc
¬abbbbbc
2. Construct a CFG for a
n
b
n
; n>0
 = {ab,aabb,aaabbb..}
V=S
S=S
T={a,b}
P: S ¬aSb
S ¬Є
ab aabb
S ¬aSb S ¬aSb
¬aЄb ¬aaSbb
¬ab ¬aaЄbb
¬aabb
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Context Free Grammar
PAGE 24
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
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
P: S ¬B1
B ¬0B
B ¬Є
1 0001
S ¬B1 S ¬B1
¬Є1 ¬0B1
¬1 ¬00B1
¬000B1
¬000Є1
¬0001
b. (0+1)*
S ¬1s|0s
S ¬Є
01 111001
S ¬0s S ¬1s
¬01s ¬11s
¬01Є ¬111s
¬01 ¬1110s
¬11100s
¬111001s
¬111001Є
¬111001
c. a
m
b
n
| m>= n
S ¬aMb
M ¬aMb | aM | Є
aabb aaabb
S ¬aMb S ¬aMb
¬aaMbb ¬aaMbb
¬aaЄbb ¬aaaMbb
¬aabb ¬aaaЄbb
¬aaabb
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Context Free Grammar PAGE 25
d. S ¬Є | 0 | 1
S ¬1s1 | 0s0
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
00 101 00100
S ¬0s0 S ¬1s1 S ¬0s0
¬0Є0 ¬101 ¬00s00
¬00 ¬00100
e. za
n
zb
n
z | n>=0
zzz zaazbbz
S ¬aSb S ¬aSb
¬aЄb ¬aaSbb
¬ab ¬aaЄbb
¬aabb
f. set of integers (+ or -)
S ¬+N| -N
S ¬0N | … | 9N | 0 | … | 9
+10 -987
S ¬+N S ¬-N
¬+1N ¬-9N
¬+10 ¬-98N
¬-987
g. {a
n
b
n
c
m
d
m
| n,m > 0}
S ¬abcd| aMbcNd
M ¬aMb | Є
N ¬aNb | Є
aabbcd aabbccdd
S ¬aMbcNd S ¬aMbcNd
¬aaMbbcЄd ¬aaMbbccNdd
¬aaЄbbcd ¬aaЄbbccЄdd
¬aabbcd ¬aabbccdd
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY-Context Free Grammar PAGE 26
or
S ¬MN
M ¬aMb |ab
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
N ¬cNd | cd
aabbcd
S ¬MN
¬aMbcd
¬aabbcd
h. {x
m
yx
m
| m >= 0}
S ¬xSx |y
xyx xxxyxxx
S ¬xSx S ¬xSx
¬xyx ¬xxSxx
¬xxxSxxx
¬xxxyxxx
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE 27
PUSHDOWN AUTOMATA
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
= Context Free Grammar’s machine counterpart.(Just as the RE have an equivalent
autometon-FA).
= Non deterministic device.(Deterministic version is only a subset of all CFL’s).
= Have input tape, finite control and a stack
= Essentially a FA with control of both input and stack “FILO” list.
Stack – is a string of symbols from some alphabet. The leftmost symbol of the stack is
considered to be the “tape” of the stack.
MOVES
1. An input symbol is used.
⇒ Depending on the input symbol, the top symbol on the stack, and state of the
finite control, a number of choices are possible. Each choice consist of next state
for the finite control and a (possibly empty) string of symbols to replace the top
stack 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 is
not advanced after the move.
⇒ Allows the PDA to manipulate the stack without reading input symbols.
WAYS TO DEFINE THE LANGUAGE ACCEPTED BY PDA  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. Sanchez
2003
AUTOMATA THEORY-Push Down Automata PAGE 28
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

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, Є, Є ) Accepted

(q1,Є,BBGGBBR) (q2,Є,GGBBR)

? ?
Prepared by: Marilyn M. Sanchez
2003
AUTOMATA THEORY PAGE29
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
TURING MACHINE
M = (Q, Σ, Г, δ, qo, B, F)
where:
Q = finite set of all sets
Г = finite set of allowable tape symbols
B = in Г, is blank
Σ = ⊆ Г not including B, set of input symbols
q0 = in Q, start state
Zo = 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 that
scans 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 symbols
chosen from a subset of the tape symbols called input symbols.
• The remaining infinity of cells each hold blank, which is a special tape symbol
that is not input symbol.

Finite Control
Basi c Turi ng Machi ne
In one move, the TM (depending upon the symbol scanned by th tape head & the state of finite
control)
1. changes state
2. prints symbol on the tape cell scanned, replacing what was written there
3. moves its head left or right one cell
Prepared by: Marilyn M. Sanchez
2003

a1 a2 … a1 … an B B …
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AUTOMATA THEORY-Turi ng Machi ne PAGE
30
Language Accepted
× 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)
0 1 x Y B
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 0011
q1 x011
q1 x011
q2 x0y1
q2 x0y1
qo x0y1
q1 xxy1
q1 xxy1
q2 xxyy
q2 xxyy
qo xxyy
q3 xxyy
q3 xxyyB
q4 xxyyBB

Therefore, accepted
Prepared by: Marilyn M. Sanchez
2003
MELJUN P. CORTES--------> Theory of Automata and Formal Language

MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AUTOMATA THEORY-Turi ng Machi ne PAGE 31
2. 0011
State Head Position

qo 0011 01
q1 x01101
q1 x01101
q2 x0y101
q2 x0y101
qo x0y101
q1 xxy101
q1 xxy101
q2 xxyy01
q2 xxyy01
qo xxyy01
q3 xxyy01
q3 xxyy01
?
Therefore, not accepted
Prepared by: Marilyn M. Sanchez
2003
MELJUN P. CORTES--------> Theory of Automata and Formal Language

2012
AMA COMPUTER UNIVERSITY
Project 8, Quezon City
COLLEGE OF COMPUTER STUDIES
MANUAL
IN
AUTOMATA THEORY
Prepared by :
MELJUN P. CORTES
MSCS STUDENT