Top Banner
Theory of Automata & Formal Languages
59
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Finite automata intro

Theory of Automata &

Formal Languages

Page 2: Finite automata intro

BOOKS

Theory of computer Science: K.L.P.Mishra & N.Chandrasekharan

Intro to Automata theory, Formal languages and computation: Ullman,Hopcroft

Motwani

Elements of theory of computation Lewis & papadimitrou

Page 3: Finite automata intro

Syllabus

Introduction

Deterministic and non deterministic Finite Automata, Regular Expression,Two way finite automata,Finite automata with output,properties of regular sets,pumping lemma, closure properties,Myhill nerode theorem

Page 4: Finite automata intro

Context free Grammar: Derivation trees, Simplification forms

Pushdown automata: Def, Relationship between PDA and context free language,Properties, decision algorithms

Turing Machines: Turing machine model,Modification of turing machines,Church’s thesis,Undecidability,Recursive and recursively enumerable languages Post correspondence problems recursive functions

Page 5: Finite automata intro

Chomsky Hierarchy: Regular grammars, unrestricted grammar, context sensitive language, relationship among languages

Page 6: Finite automata intro

CPU

input memory

output memory

Program memory

temporary memory

Page 7: Finite automata intro

CPU

input memory

output memoryProgram memory

temporary memory3)( xxf

compute xx

compute xx 2

2x

42*2 z82*)( zxf

Page 8: Finite automata intro

Automaton

CPU

input memory

output memory

Program memory

temporary memory

Automaton

Page 9: Finite automata intro

input memory

output memory

temporary memory

Finite

Automaton

Page 10: Finite automata intro

Different Kinds of Automata

Automata are distinguished by the temporary memory

• Finite Automata: no temporary memory

• Pushdown Automata: stack

• Turing Machines: random access memory

Page 11: Finite automata intro

input memory

output memory

Random Access Memory

Turing

Machine

Turing Machine

Algorithms (highest computing power)

Page 12: Finite automata intro

Finite

Automata

Pushdown

Automata

Turing

Machine

Power of Automata

Page 13: Finite automata intro

Power sets

A power set is a set of sets

Powerset of S = the set of all the subsets of S

S = { a, b, c }

2S = { , {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }

Observation: | 2S | = 2|S| ( 8 = 23 )

Page 14: Finite automata intro

Cartesian ProductA = { 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|

Generalizes to more than two sets

A X B X … X Z

Page 15: Finite automata intro

RELATIONS R = {(x1, y1), (x2, y2), (x3, y3), …}

xi R yi

e. g. if R = ‘>’: 2 > 1, 3 > 2, 3 > 1

In relations xi can be repeated

Page 16: Finite automata intro

Equivalence Relations

• Reflexive: x R x

• Symmetric: x R y y R x

• Transitive: x R Y and y R z x R z

Example: R = ‘=‘

• x = x

• x = y y = x

• x = y and y = z x = z

Page 17: Finite automata intro

Equivalence ClassesFor 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) }

Equivalence class of 1 = {1, 2}

Equivalence class of 3 = {3, 4}

Page 18: Finite automata intro

Example of Equivalence relation

Let Z = set of integers

R be defined on it as:

R= {(x,y)| x Z, y Z and

(x - y)is divisible by 5}

This relation is known as

” congruent modulo 5”

Page 19: Finite automata intro

The equivalence classes are

[0]R= {…-10, -5, 0, 5,10,…}

[1]R = {…..,-9, -4, 1, 6, 11, 16….}

[2]R= {….-8, -3,2,7,12,17…..}

[3]R = {….-7, -2, 3, 8 ,13,…}

[4]R = {….-6,-1,4,9,14,19,….}

Z/R ={[0]R, [1]R, [2]R, [3]R, [4]R}

Page 20: Finite automata intro

PROOF TECHNIQUES

• Proof by induction

• Proof by contradiction

Page 21: Finite automata intro

Induction

We have statements P1, P2, P3, …

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

Page 22: Finite automata intro

Treesroot

leaf

parent

child

Trees have no cycles

Page 23: Finite automata intro

Proof by Induction• Inductive basis

Find P1, P2, …, Pk which are true

• Inductive hypothesis

Let’s assume P1, P2, …, Pn are true,

for any n >= k

• Inductive step

Show that Pn+1 is true

Page 24: Finite automata intro

root

leaf

Level 0

Level 1

Level 2

Level 3

Height 3

Page 25: Finite automata intro

Binary Trees

Page 26: Finite automata intro

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

Page 27: Finite automata intro

Induction Step

hypothesis: l(n) <= 2n

Level

n

n+1

Page 28: Finite automata intro

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

Page 29: Finite automata intro

hypothesis: l(n) <= 2n

Level

n

n+1

l(n+1) <= 2 * l(n) <= 2 * 2n = 2n+1

Induction Step

Page 30: Finite automata intro

Proof by Contradiction

We want to prove that a statement P is true

• we assume that P is false

• then we arrive at an incorrect conclusion

• therefore, statement P must be true

Page 31: Finite automata intro

Example

Theorem: is not rational

Proof:

Assume by contradiction that it is rational

= n/m

n and m have no common factors

We will show that this is impossible

2

2

Page 32: Finite automata intro

= n/m 2 m2 = n2

Therefore, n2 is evenn is even

n = 2 k

2 m2 = 4k2 m2 = 2k2m is even

m = 2 p

Thus, m and n have common factor 2

Contradiction!

2

Page 33: Finite automata intro

Basic Terms

Alphabet: A finite non empty set of elements.

={a,b,c,d,…z}

Page 34: Finite automata intro

• String: A sequence of letters

– Examples: “cat”, “dog”, “house”, …

– Defined over an alphabet:

zcba ,,,,

Language: It is a set of strings on some alphabet

Page 35: Finite automata intro

Alphabets and Strings

• We will use small alphabets:

• Strings

abbaw

bbbaaav

abu

ba,

baaabbbaaba

baba

abba

ab

a

Page 36: Finite automata intro

String Operations

m

n

bbbv

aaaw

21

21

bbbaaa

abba

mn bbbaaawv 2121

Concatenation

abbabbbaaa

Page 37: Finite automata intro

12aaaw nR

naaaw 21 ababaaabbb

Reverse

bbbaaababa

Page 38: Finite automata intro

String Length

• Length:

• Examples:

naaaw 21

nw

1

2

4

a

aa

abba

Page 39: Finite automata intro

Recursive Definition of Length

For any letter:

For any string :

Example:

1a

1wwawa

4

1111

111

11

1

a

ab

abbabba

Page 40: Finite automata intro

Length of Concatenation

• Example:

vuuv

853

8

5,

3,

vuuv

aababaabuv

vabaabv

uaabu

Page 41: Finite automata intro

Proof of Concatenation Length

• Claim:

• Proof: By induction on the length

– Induction basis:– From definition of length:

vuuv v

1v

vuuuv 1

Page 42: Finite automata intro

– Inductive hypothesis:

• for

– Inductive step: we will prove–

– for

vuuv

nv ,,2,1

1nv

vuuv

Page 43: Finite automata intro

Inductive Step

• Write , where

• From definition of length:

• From inductive hypothesis:

• Thus:

wav 1, anw

1

1

wwa

uwuwauv

wuuw

vuwauwuuv 1

Page 44: Finite automata intro

Empty String

• A string with no letters:

• Observations:

abbaabbaabba

www

0

Page 45: Finite automata intro

Substring

• Substring of string:

– a subsequence of consecutive characters

• String Substring

bbab

b

abba

ab

abbab

abbab

abbab

abbab

Page 46: Finite automata intro

Prefix and Suffix

• Prefixes Suffixesabbab

abbab

abba

abb

ab

a

b

ab

bab

bbab

abbabuvw

prefix

suffix

Page 47: Finite automata intro

Another Operation

• Example:

• Definition:–

n

n wwww

abbaabbaabba 2

0w

0abba

Page 48: Finite automata intro

The * Operation

• : the set of all possible strings from• alphabet

*

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

Page 49: Finite automata intro

The + Operation : the set of all possible strings from alphabet except

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

*

,,,,,,,, aabaaabbbaabaaba

Page 50: Finite automata intro

Language

• A language is any subset of

• Example:

• Languages:

* ,,,,,,,,*

,

aaabbbaabaaba

ba

},,,,,{

,,

aaaaaaabaababaabba

aabaaa

Page 51: Finite automata intro

Another Example

• An infinite language

}0:{ nbaL nn

aaaaabbbbb

aabb

ab

L Labb

Page 52: Finite automata intro

Operations on Languages

• The usual set operations

• Complement:

aaaaaabbbaaaaaba

ababbbaaaaaba

aaaabbabaabbbaaaaaba

,,,,

}{,,,

},,,{,,,

LL * ,,,,,,, aaabbabaabbaa

Page 53: Finite automata intro

Reverse

• Definition:

• Examples:

}:{ LwwL RR

ababbaabababaaabab R ,,,,

}0:{

}0:{

nabL

nbaL

nnR

nn

Page 54: Finite automata intro

Concatenation

• Definition:

• Example:

2121 ,: LyLxxyLL

baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

Page 55: Finite automata intro

Another Operation

• Definition:

• Special case:

n

n LLLL

bbbbbababbaaabbabaaabaaa

babababa

,,,,,,,

,,,, 3

0

0

,, aaabbaa

L

Page 56: Finite automata intro

More Examples

• }0:{ nbaL nn

}0,:{2 mnbabaL mmnn

2Laabbaaabbb

Page 57: Finite automata intro

Star-Closure (Kleene *)

• Definition:

• Example:

210* LLLL

,,,,

,,,,

,,

,

*,

abbbbabbaaabbaaa

bbbbbbaabbaa

bbabba

Page 58: Finite automata intro

Positive Closure

• Definition:

*

21

L

LLL

,,,,

,,,,

,,

,

abbbbabbaaabbaaa

bbbbbbaabbaa

bba

bba

Page 59: Finite automata intro

Finite AutomatonInput

String

Output

String

FiniteAutomaton