Professional Documents
Culture Documents
Theory of Automata & Formal Languages
Theory of Automata & Formal Languages
&
Formal Languages
BOOKS
Theory of computer Science: K.L.P.Mishra &
N.Chandrasekharan
input memory
CPU
output memory
Program memory
3
temporary memory f ( x) = x
z = 2*2 = 4
f ( x) = z * 2 = 8
input memory
x=2
CPU
output memory
Program memory
compute x∗x
2
compute x ∗x
Automaton
temporary memory
Automaton
input memory
CPU
output memory
Program memory
temporary memory
input memory
Finite
Automaton
output memory
Different Kinds of Automata
Automata are distinguished by the temporary memory
input memory
Turing
Machine
output memory
S = { a, b, c }
2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }
Observation: | 2S | = 2|S| ( 8 = 23 )
Cartesian Product
A = { 2, 4 } B = { 2, 3, 5 }
A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 4) }
|A X B| = |A| |B|
AXBX…XZ
RELATIONS
R = {(x1, y1), (x2, y2), (x3, y3), …}
xi R yi
Example: R = ‘=‘
•x=x
•x=y y=x
• x = y and y = z x=z
Equivalence Classes
For equivalence relation R
equivalence class of x = {y : x R y}
Example:
R = { (1, 1), (2, 2), (1, 2), (2, 1),
(3, 3), (4, 4), (3, 4), (4, 3) }
• Proof by induction
• Proof by contradiction
Induction
If we know
• for some k that P1, P2, …, Pk are true
• for any n >= k that
P1, P2, …, Pn imply Pn+1
Then
Every Pi is true
Trees
root
parent
leaf
child
• Inductive hypothesis
Let’s assume P1, P2, …, Pn are true,
for any n >= k
• Inductive step
Show that Pn+1 is true
root
Level 0
Level 1
leaf Height 3
Level 2
Level 3
Binary Trees
Example
Theorem: A binary tree of height n
has at most 2n leaves.
Proof:
let l(i) be the number of leaves at level i
l(0) = 0
l(3) = 8
Induction Step
Level
n hypothesis: l(n) <= 2n
n+1
We want to show: l(i) <= 2i
• Inductive basis
l(0) = 1 (the root node)
• Inductive hypothesis
Let’s assume l(i) <= 2i for all i = 0, 1, …, n
• Induction step
we need to show that l(n + 1) <= 2n+1
Induction Step
Level
n hypothesis: l(n) <= 2n
n+1
Proof:
Assume by contradiction that it is rational
2 = n/m
n and m have no common factors
n is even
Therefore, n2 is even
n=2k
m is even
2 m2 = 4k2 m2 = 2k2
m=2p
Contradiction!
Basic Terms
Alphabet: A finite non empty set of
elements.
∑∑ ={a,b,c,d,…z}
∑
Concatenation
Reverse
R
w = an a2 a1 bbbaaababa
String Length
w = a1a2 an
w =n
• Length:
abba = 4
• Examples: aa = 2
a =1
Recursive Definition of Length
a =1
For any letter:
wa wa = w + 1
For any string : abba = abb + 1
= ab + 1 + 1
Example:
= a +1+1+1
= 1+1+1+1
=4
Length of Concatenation
uv = u + v
u = aab, u = 3
v = abaab,
• Example: v =5
uv = aababaab = 8
uv = u + v = 3 + 5 = 8
Proof of Concatenation Length
uv = u + v
• Claim:
v
• Proof: By induction on the length
v =1
– Induction basis:
– From definition of length:
uv = u +1 = u + v
uv = u + v
– Inductive hypothesis:
v = 1,2,, n
• for
• Thus:
uv = u + w + 1 = u + wa = u + v
Empty String
λ
• A string with no letters:
λ =0
• Observations:
λw = wλ = w
ab bab suffix
abb ab
abba b
abbab λ
Another Operation
wn = ww
w
n
( abba ) = abbaabba
2
• Example:
0
• Definition:
w = λ
–
( abba ) = λ
0
The * Operation
• Σ * : the set of all possible strings from
• Σ alphabet
Σ = { a, b}
Σ* = { λ, a, b, aa, ab, ba, bb, aaa, aab,}
•
The + Operation
+ : the set of all possible strings from
Σ
alphabet Σ except λ
Σ = { a, b}
Σ* = { λ , a, b, aa, ab, ba, bb, aaa, aab,}
+
Σ = Σ * −λ
+
Σ = { a, b, aa, ab, ba, bb, aaa, aab,}
Language
{ λ}
{ a, aa, aab}
• Languages:
{λ , abba, baba, aa, ab, aaaaaa}
Another Example
n n
L = {a b : n ≥ 0}
• An infinite language
λ
ab
∈L abb ∉ L
aabb
aaaaabbbbb
Operations on Languages
•
{ ab, aab, baba} = { ba, baa, abab}
Examples:
R
n n
L = {a b : n ≥ 0}
R n n
L = {b a : n ≥ 0}
Concatenation
L1L2 = { xy : x ∈ L1, y ∈ L2 }
• Definition:
L0 = { λ}
• Special case:
0
{ a , bba , aaa } = { λ}
More Examples
n n
• L = {a b : n ≥ 0}
2 n n m m
L = {a b a b : n, m ≥ 0}
2
aabbaaabbb ∈ L
Star-Closure (Kleene *)
0 1 2
L* = L L L
• Definition:
• Example: λ ,
a, bb,
{ a, bb} * =
aa , abb , bba , bbbb ,
•
aaa, aabb, abba, abbbb,
Positive Closure
+ 1 2
L = L L
• Definition: = L * −{ λ }
a, bb,
+
{ a, bb} = aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
Finite Automaton
Input
•
String
Output
Finite String
Automaton