SlideShare a Scribd company logo
1 of 23
Free Ebooks Download
Mba Ebooks By Edhole
Mba ebooks
Free ebooks download
http://ebooks.edhole.com
Examples for Context-free Language and
Pumping Lemma
CSC3130 Tutorial 5
Xiao Linfu
lfxiao@cse.cuhk.edu.hk
Department of Computer Science &
Engineering
Fall 2009
http://ebooks.edhole.com
Outline
• Context-free Languages, Context-free grammars
(CFG), Push-down Automata (PDA)
• Pumping lemma
http://ebooks.edhole.com
Relations
Context free
language
regular
language
http://ebooks.edhole.com
Relations
Context-free
Languages L
Context-free
Grammars G
Push-down
Automata M
L = L(G)
L = L(M) L(G) = L(M)
http://ebooks.edhole.com
What we should know?
• Given a Language L
– NOT context-free – proof by pumping lemma
– context-free – design Pushdown Automata and context-
free grammar
• NOT regular – proof by pumping lemma
• regular – design DFA / NFA / RE
http://ebooks.edhole.com
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}
http://ebooks.edhole.com
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 = { ai
bj
; i>j }
Lx = { ai
bj
; i<j }
L(S) =
{ ai
bj
; i≠j }
http://ebooks.edhole.com
Example (I) --- solution: PDA
S  X | Y
X  aXb | aX | a
Y  aYb | Yb | b
L(S) = { ai
bj
; i≠j }
PDA = NFA + a stack (infinite memory)
= { ai
bj
; i>j } U { ai
bj
; i<j }
A possible way: “divide and conquer”
Lx = { ai
bj
; i>j }
a,ε/A
q0
ε,ε/$ ε,ε/ε
q1
b,A/ε
b,$/$
q2
b,$/$
q3
ε,$/ε
LY = { ai
bj
; i<j }
q’0
ε,ε/$ ε,ε/ε
q’1
ε,A/ε
q’2
ε,A/ε
q’3
ε,$/ε
a,ε/A b,A/ε
ε, ε /ε
Combine both …
http://ebooks.edhole.com
Example (II)
• Given the following language:
• (1) design a CFG for it;
• (2) design a PDA for it.
L = {0i
1j
: i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1}
http://ebooks.edhole.com
Example (II) -- solution: CFG
L = {0i
1j
: i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1}
Consider two extreme cases:
(a). if j = i, then L1 = { 0i
1j
: i=j }; (b). if j = 2i, then L2 = { 0i
1j
:
2i=j }.
S  0S1
S  ε
S  0S11
S  ε
If i ≤ j ≤ 2i , then randomly choose “red-
rule” or “blue-rule” in the generation.
“red-rule” “blue-rule”
S  0S1
S  0S11
S  ε http://ebooks.edhole.com
Example (II) -- solution: CFG
L = {0i
1j
: i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1}
S  0S1 S  0S11 S  ε
Need to verify L = L(G)
G =
1). L(G) is a subset of L:
The “red-rule” and “blue-rule” guarantee that in each derivation,
the number of 1s generated is one or two times larger than that
of 0s. So, L(G) is a subset of L.
2). L is a subset of L(G):
For any w = 0i
1j
, i ≤ j ≤ 2i, we use “red-rule” (2i - j) times and
then “blue-rule” ( j - i ) times, i.e.,
S =*=> 02i-j
S12i-j
=*=> 02i-j
0j-i
S12(j-i)
12i-j
==> 0i
1j
= whttp://ebooks.edhole.com
Example (II) -- solution: PDA
L = {0i
1j
: i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1}
Similar idea: “randomly choose two extreme cases”
q0
ε,ε/$
0,ε/X
ε,ε/ε q1
q2
ε,$/ε
1,X/ε
1,X/X 1,X/ε
q3
http://ebooks.edhole.com
Example (III)
• Given the following language:
• (1). Design a CFG for it;
• (2). Design a PDA for it.
L = { ai
bj
ck
dl
: i, j, k, l=0,1,…; i+k=j+l },
where the alphabet Σ= {a, b, c, d}
http://ebooks.edhole.com
Example (III) – solution: CFG
L = { ai
bj
ck
dl
: i,j,k,l=0,1,…; i+k=j+l },
Note that i + k = j + l ==> | i – j | = | l – k |.
Assume n = i – j = l – k > 0, then i = n + j, l = n + k, and
w = ai
bj
ck
dl
= an
aj
bj
ck
dk
dn
w
an
dn
aj
bj
ck
dk
aj
bj
ck
dk
Three blocks come from
the same template:
N  x N x
S  aSd | XY
X  aXb | ε
Y  cYd | ε
S-->an
Sdn
--> an
XYdn
-->an
aj
bj
Ydn
-->an
aj
bj
ck
bk
dn
= an+j
bj
ck
bn+k
(n+j) + k = j + (n+k)
http://ebooks.edhole.com
Example (III) – solution: PDA
L = { ai
bj
ck
dl
: 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.
http://ebooks.edhole.com
Example (III) – solution: PDA
L = { ai
bj
ck
dl
: 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.
ε,ε/$
q5
q1
a,ε/X
ε,ε/ε
b,$/Y$
q2
ε,ε/ε
c,X/XX
q3
ε,ε/ε q4
ε, $ /ε
b,X/ε
b,Y/YY
c,$/X$
c,Y/ε
d,X/ε
d,$/Y$
d,Y/YY
http://ebooks.edhole.com
Outline
• Context-free Languages, Context-free grammars
(CFG), Push-down Automata (PDA)
• Pumping Lemma
http://ebooks.edhole.com
Pumping lemma for context-free languages
• Theorem: For every context-free language L
There exists a number n such that for every
string z in L, we can write z = uvwxy where
 |vwx| ≤ n
 |vx| ≥ 1
 For every i ≥ 0, the string uvi
wxi
y is in L.
wu yxv
http://ebooks.edhole.com
Example(4)
1
2
L1 = {0n
1n
0n
1n
| n 0≥ }
wu yxv
0 0 ... 0 0 1 1 …1 1 1 0 0 … 0 0 11 …11
choose n
write z = uvwxy
z = 0n
1n
0n
1n
i = 2
1. Neither v nor x can contain both 0 and 1
We try to argue that z = uv2
wx2
y is NOT in L1
http://ebooks.edhole.com
Example(5)
1
2
L2 = {0n
#02n
#3n
| n ≥ 0 }
wu yxv
0 0 ... 0 0 # 0 0 …0 0 0 # 0 0 0 0 … 0 0 0 0
choose n
write z = uvwxy
z = 0n
#02n
#03n
i = 2
1. Neither v nor x can contain #
2. 1:2:3 ratio can’t be maintained since at least
one segment NOT in v and x
We try to argue that z = uv2
wx2
y is NOT in L2
http://ebooks.edhole.com
End of this tutorial!
Thanks for coming!
http://ebooks.edhole.com
Free Ebooks Download
Mba Ebooks By Edhole
Mba ebooks
Free ebooks download
http://ebooks.edhole.com

More Related Content

More from Edhole.com

Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarkaEdhole.com
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarkaEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbaiEdhole.com
 
Website development company surat
Website development company suratWebsite development company surat
Website development company suratEdhole.com
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in suratEdhole.com
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in indiaEdhole.com
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhiEdhole.com
 
Video lectures for mba
Video lectures for mbaVideo lectures for mba
Video lectures for mbaEdhole.com
 
Video lecture for b.tech
Video lecture for b.techVideo lecture for b.tech
Video lecture for b.techEdhole.com
 
Video lecture for bca
Video lecture for bcaVideo lecture for bca
Video lecture for bcaEdhole.com
 
Mba top schools in india
Mba top schools in indiaMba top schools in india
Mba top schools in indiaEdhole.com
 

More from Edhole.com (20)

Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website dsigning company in india
Website dsigning company in indiaWebsite dsigning company in india
Website dsigning company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Ca in patna
Ca in patnaCa in patna
Ca in patna
 
Chartered accountant in dwarka
Chartered accountant in dwarkaChartered accountant in dwarka
Chartered accountant in dwarka
 
Ca firm in dwarka
Ca firm in dwarkaCa firm in dwarka
Ca firm in dwarka
 
Ca in dwarka
Ca in dwarkaCa in dwarka
Ca in dwarka
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website designing company in surat
Website designing company in suratWebsite designing company in surat
Website designing company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Website designing company in mumbai
Website designing company in mumbaiWebsite designing company in mumbai
Website designing company in mumbai
 
Website development company surat
Website development company suratWebsite development company surat
Website development company surat
 
Website desinging company in surat
Website desinging company in suratWebsite desinging company in surat
Website desinging company in surat
 
Website designing company in india
Website designing company in indiaWebsite designing company in india
Website designing company in india
 
Website designing company in delhi
Website designing company in delhiWebsite designing company in delhi
Website designing company in delhi
 
Video lectures for mba
Video lectures for mbaVideo lectures for mba
Video lectures for mba
 
Video lecture for b.tech
Video lecture for b.techVideo lecture for b.tech
Video lecture for b.tech
 
Video lecture for bca
Video lecture for bcaVideo lecture for bca
Video lecture for bca
 
Mba top schools in india
Mba top schools in indiaMba top schools in india
Mba top schools in india
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Free Ebooks Download ! Edhole

  • 1. Free Ebooks Download Mba Ebooks By Edhole Mba ebooks Free ebooks download http://ebooks.edhole.com
  • 2. Examples for Context-free Language and Pumping Lemma CSC3130 Tutorial 5 Xiao Linfu lfxiao@cse.cuhk.edu.hk Department of Computer Science & Engineering Fall 2009 http://ebooks.edhole.com
  • 3. Outline • Context-free Languages, Context-free grammars (CFG), Push-down Automata (PDA) • Pumping lemma http://ebooks.edhole.com
  • 5. Relations Context-free Languages L Context-free Grammars G Push-down Automata M L = L(G) L = L(M) L(G) = L(M) http://ebooks.edhole.com
  • 6. What we should know? • Given a Language L – NOT context-free – proof by pumping lemma – context-free – design Pushdown Automata and context- free grammar • NOT regular – proof by pumping lemma • regular – design DFA / NFA / RE http://ebooks.edhole.com
  • 7. 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} http://ebooks.edhole.com
  • 8. 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 = { ai bj ; i>j } Lx = { ai bj ; i<j } L(S) = { ai bj ; i≠j } http://ebooks.edhole.com
  • 9. Example (I) --- solution: PDA S  X | Y X  aXb | aX | a Y  aYb | Yb | b L(S) = { ai bj ; i≠j } PDA = NFA + a stack (infinite memory) = { ai bj ; i>j } U { ai bj ; i<j } A possible way: “divide and conquer” Lx = { ai bj ; i>j } a,ε/A q0 ε,ε/$ ε,ε/ε q1 b,A/ε b,$/$ q2 b,$/$ q3 ε,$/ε LY = { ai bj ; i<j } q’0 ε,ε/$ ε,ε/ε q’1 ε,A/ε q’2 ε,A/ε q’3 ε,$/ε a,ε/A b,A/ε ε, ε /ε Combine both … http://ebooks.edhole.com
  • 10. Example (II) • Given the following language: • (1) design a CFG for it; • (2) design a PDA for it. L = {0i 1j : i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1} http://ebooks.edhole.com
  • 11. Example (II) -- solution: CFG L = {0i 1j : i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1} Consider two extreme cases: (a). if j = i, then L1 = { 0i 1j : i=j }; (b). if j = 2i, then L2 = { 0i 1j : 2i=j }. S  0S1 S  ε S  0S11 S  ε If i ≤ j ≤ 2i , then randomly choose “red- rule” or “blue-rule” in the generation. “red-rule” “blue-rule” S  0S1 S  0S11 S  ε http://ebooks.edhole.com
  • 12. Example (II) -- solution: CFG L = {0i 1j : i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1} S  0S1 S  0S11 S  ε Need to verify L = L(G) G = 1). L(G) is a subset of L: The “red-rule” and “blue-rule” guarantee that in each derivation, the number of 1s generated is one or two times larger than that of 0s. So, L(G) is a subset of L. 2). L is a subset of L(G): For any w = 0i 1j , i ≤ j ≤ 2i, we use “red-rule” (2i - j) times and then “blue-rule” ( j - i ) times, i.e., S =*=> 02i-j S12i-j =*=> 02i-j 0j-i S12(j-i) 12i-j ==> 0i 1j = whttp://ebooks.edhole.com
  • 13. Example (II) -- solution: PDA L = {0i 1j : i ≤ j ≤ 2i, i=0,1,…}, Σ = {0, 1} Similar idea: “randomly choose two extreme cases” q0 ε,ε/$ 0,ε/X ε,ε/ε q1 q2 ε,$/ε 1,X/ε 1,X/X 1,X/ε q3 http://ebooks.edhole.com
  • 14. Example (III) • Given the following language: • (1). Design a CFG for it; • (2). Design a PDA for it. L = { ai bj ck dl : i, j, k, l=0,1,…; i+k=j+l }, where the alphabet Σ= {a, b, c, d} http://ebooks.edhole.com
  • 15. Example (III) – solution: CFG L = { ai bj ck dl : i,j,k,l=0,1,…; i+k=j+l }, Note that i + k = j + l ==> | i – j | = | l – k |. Assume n = i – j = l – k > 0, then i = n + j, l = n + k, and w = ai bj ck dl = an aj bj ck dk dn w an dn aj bj ck dk aj bj ck dk Three blocks come from the same template: N  x N x S  aSd | XY X  aXb | ε Y  cYd | ε S-->an Sdn --> an XYdn -->an aj bj Ydn -->an aj bj ck bk dn = an+j bj ck bn+k (n+j) + k = j + (n+k) http://ebooks.edhole.com
  • 16. Example (III) – solution: PDA L = { ai bj ck dl : 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. http://ebooks.edhole.com
  • 17. Example (III) – solution: PDA L = { ai bj ck dl : 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. ε,ε/$ q5 q1 a,ε/X ε,ε/ε b,$/Y$ q2 ε,ε/ε c,X/XX q3 ε,ε/ε q4 ε, $ /ε b,X/ε b,Y/YY c,$/X$ c,Y/ε d,X/ε d,$/Y$ d,Y/YY http://ebooks.edhole.com
  • 18. Outline • Context-free Languages, Context-free grammars (CFG), Push-down Automata (PDA) • Pumping Lemma http://ebooks.edhole.com
  • 19. Pumping lemma for context-free languages • Theorem: For every context-free language L There exists a number n such that for every string z in L, we can write z = uvwxy where  |vwx| ≤ n  |vx| ≥ 1  For every i ≥ 0, the string uvi wxi y is in L. wu yxv http://ebooks.edhole.com
  • 20. Example(4) 1 2 L1 = {0n 1n 0n 1n | n 0≥ } wu yxv 0 0 ... 0 0 1 1 …1 1 1 0 0 … 0 0 11 …11 choose n write z = uvwxy z = 0n 1n 0n 1n i = 2 1. Neither v nor x can contain both 0 and 1 We try to argue that z = uv2 wx2 y is NOT in L1 http://ebooks.edhole.com
  • 21. Example(5) 1 2 L2 = {0n #02n #3n | n ≥ 0 } wu yxv 0 0 ... 0 0 # 0 0 …0 0 0 # 0 0 0 0 … 0 0 0 0 choose n write z = uvwxy z = 0n #02n #03n i = 2 1. Neither v nor x can contain # 2. 1:2:3 ratio can’t be maintained since at least one segment NOT in v and x We try to argue that z = uv2 wx2 y is NOT in L2 http://ebooks.edhole.com
  • 22. End of this tutorial! Thanks for coming! http://ebooks.edhole.com
  • 23. Free Ebooks Download Mba Ebooks By Edhole Mba ebooks Free ebooks download http://ebooks.edhole.com