Automata Theory - Automata and Complexity Theory - Lecture Slides, Slides of Theory of Automata

Some concept of Automata and Complexity Theory are Administrivia, Closure Properties, Context-Free Grammars, Decision Properties, Deterministic Finite Automata, Intractable Problems, More Undecidable Problems. Main points of this lecture are: Automata Theory, Formal Languages, Context-Free Languages, Push-Down Automata, Grammars, Grammar Transformations, Remove, Production, Remove Unit-Production, Covert to Chomsky-Normal-Form

Typology: Slides

2012/2013

Uploaded on 04/29/2013

juni
juni 🇮🇳

4

(17)

122 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Formal Languages and Automata Theory
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Automata Theory - Automata and Complexity Theory - Lecture Slides and more Slides Theory of Automata in PDF only on Docsity!

Formal Languages and Automata Theory

Outline

• Context-free Languages, Context-free

grammars (CFG), Push-down Automata (PDA)

• Grammar Transformations

– Remove ε- production;

– Remove unit-production;

– Covert to Chomsky-Normal-Form (CNF)

• Cocke-Younger-Kasami (CYK) algorithm

Example (I)

• Given the following CFG

S  X | Y

X  aXb | aX | a

Y  aYb | Yb | b

• (1) L(G) =?

• (2) Design an equivalent PDA for it.

Σ={a, b}

Example (I) --- solution: L(S)

S  X | Y

X  aXb | aX | a

Y  aYb | Yb | b

Try to write some strings generated by it: SXaXbaaXbbaaaXbbaaaabb SYaYbaYbbaaYbbbaabbbb

more a ’s than b ’s more b ’s than a ’s

Observations:

  • Start from S, we can enter two States X & Y, and X, Y are “independent”;
  • In X state, always more a are generated;
  • In Y state, always more b are generated.

Ls = Lx U Ly

Lx = { a ib j^ ; i>j } Lx = { a ib j^ ; i<j }

L(S) =

{ aibj; i≠j }

Example (II)

• Given the following language:

• (1) design a CFG for it;

• (2) design a PDA for it.

L = {0 i 1 j : i ≤ j ≤ 2 i, i=0,1,… }, Σ = {0, 1}

Example (II) -- solution: CFG

L = {0 i 1 j : i ≤ j ≤ 2 i, i=0,1,… }, Σ = {0, 1}

Consider two extreme cases:

(a). if j = i, then L 1 = { 0i 1 j: i=j }; (b). if j = 2i, then L 2 = { 0i 1 j: 2i=j }.

S  0S

S  ε

S  0S

S  ε If ij ≤ 2 i , then randomly choose “ red- rule ” or “ blue-rule ” in the generation.

red-rule ” “ blue-rule

S  0S
S  0S

S  ε

Example (II) -- solution: PDA

L = {0 i 1 j : i ≤ j ≤ 2 i, i=0,1,… }, Σ = {0, 1}

Similar idea: “randomly choose two extreme cases”

ε,ε/# q (^0)

0,ε/X ε,ε/ε q^1

q (^2)

ε,#/ε

1,X/ε

1,X/X 1,X/ε

q (^3)

Example (III)

• Given the following language:

• (1). Design a CFG for it;

• (2). Design a PDA for it.

L = { a i b j c k d l : i , j,k,l=0,1 ,…; i+k=j+l },

where the alphabet Σ= {a, b, c, d}

Example (III) – solution: PDA

L = { a i b j c k d l : i , j,k,l=0,1 ,…; i+k=j+l },

Main idea: (1) use X to record an a or c ; use Y to record an b or d. (2) Compare # X and # Y : by cancellation.

How to realize the comparison by cancellation? Action1: Push an X, when a or c was read; Action2: Pop an X (if any, otherwise push a Y), when b or d was read. Action3: Pop an Y (if any, otherwise push an X), when a or c was read.

Example (III) – solution: PDA

L = { a i b j c k d l : i , j,k,l=0,1 ,…; i+k=j+l },

Action1: Push an X, when a or c was read; Action2: Pop an X (if any, otherwise push a Y), when b or d was read. Action3: Pop an Y (if any, otherwise push an X), when a or c was read.

ε,ε/# (^) q (^1) q (^5)

a,ε/X ε,ε/ε

b,#/Y#

q 2 ε,ε/ε

c,X/XX

q 3 ε,ε/ε^ q 4 ε,#/ε

b,X/ε

b,Y/YY

c,#/X#

c,Y/ε

d,X/ε

d,#/Y# d,Y/YY

Remove ε-production

• Example:

Remove ε-productions of the

following grammar G:

S → ABaC

A → BC

B → b |ε

C → D |ε

D → d

Remove ε-production

S → ABaC | BaC

| AaC | aC

| ABa | Ba | Aa | a

A → BC | C | B

B → b |ε

C → D |ε

D → d

Nullable variables: A, B, C Add Delete For A : S  BaC For B : S  AaC | aC A  C

B → ε

For C : S  ABa | Ba | Aa | a A  B

C → ε

For i = 1 to k

For every production of the form A → αN i β,

add another production A → αβ

If N i → ε is a production, remove it Docsity.com

Remove unit-productions

Add Delete

S  T

For T TF (^) S  TF For T F  a (^) S  a

S → S+T | T

| T*F | a | ( S )

T → T*F | F

| a | ( S )

F → ( S ) | a

For T F  (S) (^) S  (S) T  F For F  a (^) S  a For F  (S) (^) S  (S)

A 1 → A 2 → ... → A k → A 1

A 1 → A 2 → ... → A k → α A 1 →^ α,... , Ak →^ α

delete it and replace

Rule 1: everything with A 1

Rule 2:

Convert CFG to Chomsky-Normal-Form

(CNF)

  • Example: Convert the following CFG to CNF:

S  0AB

A  0D | 1AD

B  0

D  1