SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
Sri vidya college of engineering and technology Lecture notes
CS6503 Theory of computation Unit II
UNIT II CONTEXT FREE GRAMMER
1. Let G = ( {S,C}, {a,b}, P,S} where P consists of S aCa, CaCa, Find L(G))?
Solution:
S aCa
aaCaa CaCa
.
.
anCan
anban C b
L (G) = { anban ; n >0}
2. Consider G whose productions are SaAS/ a ,ASbA / SS / ba, show that aabbaa
and
construct a derivation tree.
Solution: S
S aAs
aSbAs A SbA a A S
aabAS S a a
aabbaS Aba S b A
aabbaa Sa
a b a
3. Find L(G) where G = ({S},{0,1}, {S0S1, sε },S)
Solution:
S 0S1
00S11
.
.
.
0nS1n
L (G) = { 0n1n ; n >0}
4. Define a derivation tree for CFG.
A derivation tree for a CFG G=(V,T,P,S) is a tree satisfying the following
Every vertex has a label, which is a symbol of V U T U ε
The label of the root is S.
If a vertex is interior and has a label A, then A must be in V.
If n has a label A and vertices n1, n2,……nk are sons of the vertex n, in
x1,x2,……xk must be a production in P.
If vertex n has label ε, then n is a leaf and is the only son of its father.
5. Construct CFG L= { anbn ; n≥1}.
Solution:
The Production are
S aSb / ε, where G= ({S}, {a,b,ε}, P, S)
Sri vidya college of engineering and technology Lecture notes
CS6503 Theory of computation Unit II
6. Find a LM derivation for aaabbabbba with the productions.
P : S aB / bA, A a /S / bAA, B b / bS / aBB
Solution:
S aB aaBB aaaBBBaaabBBaaaabbBaaabbaBBaaabbabB
aaabbabbS aaabbabbbA
S aaabbabbba
7. Find L(G), S aSb, S ab.
Solution:
S aSb
aaSbb CaSb
.
.
anSbn
anbn C ab
L (G) = { anbn ; n ≥1}
8. Show that id* id can be generated by two distinct leftmost derivation in the grammar
EE+E / E*E / (E) / id
Solution:
(i) E E +E (ii) E E *E
id+E E +E*E
id+E*E E+E*id
id+id*E E+id*id
id+id*id id+id*id
We showed that id+id*id can be generated by two distinct LMD.
9. Define pushdown automaton.
A Pushdown Automata is a finite automation with extra resource called stack.
It consists of 7 tuples.
P = (Q, Σ, , , q0, Z0, F)
Where
Q – Finite set of states
Σ - Finite set of input symbols
- Finite set of stack symbols
- Transition function
q0 – Start State
Z0 – Start symbol of the stack
F – Final State.
10. What are the different ways of language acceptances by a PDA and define them.
i) Acceptance by final state
L (M) = { w | (q0, w, z0) |--*(p, ε, ) for some P in F and in |--*}
ii) Acceptance by empty stack
N (M) = { w | (q0, w, z0) |--*(p, ε, ε ) for some P in Q}
Sri vidya college of engineering and technology Lecture notes
CS6503 Theory of computation Unit II
PART-A
1. Define CFG.2.Find L(G)where G=({S},{0,1},{S->0S1,S->ε},S).
2. Define derivation tree for a CFG(or)Define parse tree.
3. Construct the CFG for generating the language L={a
n
b
n
/n>=1}.
4. Let G be the grammar S->aB/bA,A->a/aS/bAA,B->b/bS/aBB.for the string
aaabbabbba find the left most derivation.
5. Let G be the grammar S->aB/bA,A->a/aS/bAA,B->b/bS/aBB.obtain parse tree for the
string aaabbabbba.
6. For the grammar S->aCa,C->aCa/b.Find L(G).
7. Show that id+id*id can be generated by two distinct leftmost derivation in the
grammar E->E+E | E*E | (E) | id .
8. For the grammar S->A1B,A->0A | ε, B-> 0B | 1B| ε,give leftmost and rightmost
derivations for the string 00101.
9. Find the language generated by the CFG G=({S},{0,1},{S->0/1/ ε,
S->0S0/1S1},S).
10. obtain the derivation tree for the grammar G=({S,A},{a,b},P,S) where P
consist of S->aAS / a, A->SbA / SS / ba.
11. Consider the alphabet ∑={a,b,(,),+,*, ., ε} .Construct the context free grammar
that generates all strings in ∑* that are regular expression over the alphabet
{a,b}.
12. Write the CFG to generate the set {a
m
b
n
c
p
| m + n=p and p>=1}.
13. Construct a derivation tree for the string 0011000 using the grammar
S->A0S |0 | SS , A-> S1A | 10.
14. Give an example for a context free grammar.
15. Let the production of the grammar be S-> 0B | 1A, A-> 0 | 0S | 1AA,
B-> 1|1S | 0BB.for the string 0110 find the right most derivation.
16. What is the disadvantages of unambiguous parse tree. Give an example.
PART-B
1. a) Let G be a CFG and let a=>w in G. Then show that there is a leftmost
derivation of w.
b) Let G=(V,T,P,S) be a Context free Grammar then prove that if S=> αthen there is a
derivation tree in G with yield α.
2. Let G be a grammar s->OB/1A, A->O/OS/1AA, B->1/1S/OBB. For the string
00110101 find its leftmost derivation and derivation tree.
3) a) If G is the grammar S->Sbs/a, Show that G is ambiguous.
Sri vidya college of engineering and technology Lecture notes
CS6503 Theory of computation Unit II
b) Give a detailed description of ambiguity in Context free grammar
4. a) Show that E->E+E/E*E/(E)/id is ambiguous. (6) b)Construct a Context free grammar
G which accepts N(M), where M=({q0, q1},{a,b},{z0,z},δ,q0,z0,Φ) and where δis
given by
δ(q0,b,z0)={(q0,zz0)}
δ(q0, ε,z0)={(q0, ε)}
δ(q0,b,z)={(q0,zz)}
δ(q0,a,z)={(q1,z)}
δ(q1,b,z)={(q1, ε)}
δ(q1,a,z0)={(q0,z0)}
5. a)If L is Context free language then prove that there exists PDA M such that L=N(M).
b)Explain different types of acceptance of a PDA.Are they equivalent in sense of
language acceptance? Justify your answer.
6. Construct a PDA accepting {a
n
b
m
a
n
/m,n>=1} by empty stack. Also construct the
corresponding context-free grammar accepting the same set.
7. a) Prove that L is L(M2 ) for some PDA M2 if and only if L is N(M1) for some PDA
M1.
b)Define deterministic Push Down Automata DPDA. Is it true that DPDA and PDA are
equivalent in the sense of language acceptance is concern? Justify Your answer.
8.a) Construct a equivalent grammar G in CNF for the grammar G1 where G1
=({S,A,B},{a,b},{S->bA/aB,A->bAA/aS/a, B->aBB/bS/b},S)
Sri vidya college of engineering and technology Lecture notes
CS6503 Theory of computation Unit II
b)Find the left most and right most derivation corresponding to the tree.
9. a) Find the language generated by a grammar
G=({S},{a,b},{S->aSb, S->ab},S) (4)
b) Given G=({S,A},{a,b},P,S) where P={S->AaS|S|SS,A->SbA|ba}
S-Start symbol. Find the left most and right most derivation of the string
w=aabbaaa. Also construct the derivation tree for the string w.
c) Define a PDA. Give an Example for a language accepted byPDA by empty stack.
10. G denotes the context-free grammar defined by the
following rules. ` S->ASB/ab/SS A->aA/A ,B->bB/A
(i)Give a left most derivation of aaabb in G. Draw the associated parse tree.
(ii)Give a right most derivation of aaabb in G. Draw the associated
parse tree.
(iii) Show that G is ambiguous. Explain with steps.
(iv) Construct an unambiguous grammar equivalent to G. Explain.

Contenu connexe

Similaire à QB104542.pdf

RegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptxRegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptx
RaviAr5
 

Similaire à QB104542.pdf (20)

Bt0069 discrete mathematics
Bt0069   discrete mathematicsBt0069   discrete mathematics
Bt0069 discrete mathematics
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdf
 
Bt0069 discrete mathematics
Bt0069   discrete mathematicsBt0069   discrete mathematics
Bt0069 discrete mathematics
 
Cs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer keyCs6660 compiler design november december 2016 Answer key
Cs6660 compiler design november december 2016 Answer key
 
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurMid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
 
Ch02
Ch02Ch02
Ch02
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Lesson 03
Lesson 03Lesson 03
Lesson 03
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
Probability theory
Probability theoryProbability theory
Probability theory
 
ITA 2020 - aberta
ITA 2020 - abertaITA 2020 - aberta
ITA 2020 - aberta
 
2 homework
2 homework2 homework
2 homework
 
Fuvest 2018 - aberta
Fuvest 2018 - abertaFuvest 2018 - aberta
Fuvest 2018 - aberta
 
TOC question bank.pdf
TOC question bank.pdfTOC question bank.pdf
TOC question bank.pdf
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Math
MathMath
Math
 
RegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptxRegularLanguageProperties [Autosaved].pptx
RegularLanguageProperties [Autosaved].pptx
 
Bc0039
Bc0039Bc0039
Bc0039
 
7_AJMS_246_20.pdf
7_AJMS_246_20.pdf7_AJMS_246_20.pdf
7_AJMS_246_20.pdf
 

Plus de MrRRajasekarCSE (13)

QB104545.pdf
QB104545.pdfQB104545.pdf
QB104545.pdf
 
QB104543.pdf
QB104543.pdfQB104543.pdf
QB104543.pdf
 
QB104544.pdf
QB104544.pdfQB104544.pdf
QB104544.pdf
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
Learning_Deep_Models_for_Face_Anti-Spoofing_Binary.pdf
Learning_Deep_Models_for_Face_Anti-Spoofing_Binary.pdfLearning_Deep_Models_for_Face_Anti-Spoofing_Binary.pdf
Learning_Deep_Models_for_Face_Anti-Spoofing_Binary.pdf
 
Swapna siripireddy vtu 11843 .pdf
Swapna siripireddy vtu 11843 .pdfSwapna siripireddy vtu 11843 .pdf
Swapna siripireddy vtu 11843 .pdf
 
Unit I - Theorems.pdf
Unit I - Theorems.pdfUnit I - Theorems.pdf
Unit I - Theorems.pdf
 
Swapna siripireddy vtu 11843 .pdf
Swapna siripireddy vtu 11843 .pdfSwapna siripireddy vtu 11843 .pdf
Swapna siripireddy vtu 11843 .pdf
 
R-XML.docx
R-XML.docxR-XML.docx
R-XML.docx
 
R-Json.docx
R-Json.docxR-Json.docx
R-Json.docx
 
Unit I - Theorems.pdf
Unit I - Theorems.pdfUnit I - Theorems.pdf
Unit I - Theorems.pdf
 
R-Json.docx
R-Json.docxR-Json.docx
R-Json.docx
 
R-XML.docx
R-XML.docxR-XML.docx
R-XML.docx
 

Dernier

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 

QB104542.pdf

  • 1. Sri vidya college of engineering and technology Lecture notes CS6503 Theory of computation Unit II UNIT II CONTEXT FREE GRAMMER 1. Let G = ( {S,C}, {a,b}, P,S} where P consists of S aCa, CaCa, Find L(G))? Solution: S aCa aaCaa CaCa . . anCan anban C b L (G) = { anban ; n >0} 2. Consider G whose productions are SaAS/ a ,ASbA / SS / ba, show that aabbaa and construct a derivation tree. Solution: S S aAs aSbAs A SbA a A S aabAS S a a aabbaS Aba S b A aabbaa Sa a b a 3. Find L(G) where G = ({S},{0,1}, {S0S1, sε },S) Solution: S 0S1 00S11 . . . 0nS1n L (G) = { 0n1n ; n >0} 4. Define a derivation tree for CFG. A derivation tree for a CFG G=(V,T,P,S) is a tree satisfying the following Every vertex has a label, which is a symbol of V U T U ε The label of the root is S. If a vertex is interior and has a label A, then A must be in V. If n has a label A and vertices n1, n2,……nk are sons of the vertex n, in x1,x2,……xk must be a production in P. If vertex n has label ε, then n is a leaf and is the only son of its father. 5. Construct CFG L= { anbn ; n≥1}. Solution: The Production are S aSb / ε, where G= ({S}, {a,b,ε}, P, S)
  • 2. Sri vidya college of engineering and technology Lecture notes CS6503 Theory of computation Unit II 6. Find a LM derivation for aaabbabbba with the productions. P : S aB / bA, A a /S / bAA, B b / bS / aBB Solution: S aB aaBB aaaBBBaaabBBaaaabbBaaabbaBBaaabbabB aaabbabbS aaabbabbbA S aaabbabbba 7. Find L(G), S aSb, S ab. Solution: S aSb aaSbb CaSb . . anSbn anbn C ab L (G) = { anbn ; n ≥1} 8. Show that id* id can be generated by two distinct leftmost derivation in the grammar EE+E / E*E / (E) / id Solution: (i) E E +E (ii) E E *E id+E E +E*E id+E*E E+E*id id+id*E E+id*id id+id*id id+id*id We showed that id+id*id can be generated by two distinct LMD. 9. Define pushdown automaton. A Pushdown Automata is a finite automation with extra resource called stack. It consists of 7 tuples. P = (Q, Σ, , , q0, Z0, F) Where Q – Finite set of states Σ - Finite set of input symbols - Finite set of stack symbols - Transition function q0 – Start State Z0 – Start symbol of the stack F – Final State. 10. What are the different ways of language acceptances by a PDA and define them. i) Acceptance by final state L (M) = { w | (q0, w, z0) |--*(p, ε, ) for some P in F and in |--*} ii) Acceptance by empty stack N (M) = { w | (q0, w, z0) |--*(p, ε, ε ) for some P in Q}
  • 3. Sri vidya college of engineering and technology Lecture notes CS6503 Theory of computation Unit II PART-A 1. Define CFG.2.Find L(G)where G=({S},{0,1},{S->0S1,S->ε},S). 2. Define derivation tree for a CFG(or)Define parse tree. 3. Construct the CFG for generating the language L={a n b n /n>=1}. 4. Let G be the grammar S->aB/bA,A->a/aS/bAA,B->b/bS/aBB.for the string aaabbabbba find the left most derivation. 5. Let G be the grammar S->aB/bA,A->a/aS/bAA,B->b/bS/aBB.obtain parse tree for the string aaabbabbba. 6. For the grammar S->aCa,C->aCa/b.Find L(G). 7. Show that id+id*id can be generated by two distinct leftmost derivation in the grammar E->E+E | E*E | (E) | id . 8. For the grammar S->A1B,A->0A | ε, B-> 0B | 1B| ε,give leftmost and rightmost derivations for the string 00101. 9. Find the language generated by the CFG G=({S},{0,1},{S->0/1/ ε, S->0S0/1S1},S). 10. obtain the derivation tree for the grammar G=({S,A},{a,b},P,S) where P consist of S->aAS / a, A->SbA / SS / ba. 11. Consider the alphabet ∑={a,b,(,),+,*, ., ε} .Construct the context free grammar that generates all strings in ∑* that are regular expression over the alphabet {a,b}. 12. Write the CFG to generate the set {a m b n c p | m + n=p and p>=1}. 13. Construct a derivation tree for the string 0011000 using the grammar S->A0S |0 | SS , A-> S1A | 10. 14. Give an example for a context free grammar. 15. Let the production of the grammar be S-> 0B | 1A, A-> 0 | 0S | 1AA, B-> 1|1S | 0BB.for the string 0110 find the right most derivation. 16. What is the disadvantages of unambiguous parse tree. Give an example. PART-B 1. a) Let G be a CFG and let a=>w in G. Then show that there is a leftmost derivation of w. b) Let G=(V,T,P,S) be a Context free Grammar then prove that if S=> αthen there is a derivation tree in G with yield α. 2. Let G be a grammar s->OB/1A, A->O/OS/1AA, B->1/1S/OBB. For the string 00110101 find its leftmost derivation and derivation tree. 3) a) If G is the grammar S->Sbs/a, Show that G is ambiguous.
  • 4. Sri vidya college of engineering and technology Lecture notes CS6503 Theory of computation Unit II b) Give a detailed description of ambiguity in Context free grammar 4. a) Show that E->E+E/E*E/(E)/id is ambiguous. (6) b)Construct a Context free grammar G which accepts N(M), where M=({q0, q1},{a,b},{z0,z},δ,q0,z0,Φ) and where δis given by δ(q0,b,z0)={(q0,zz0)} δ(q0, ε,z0)={(q0, ε)} δ(q0,b,z)={(q0,zz)} δ(q0,a,z)={(q1,z)} δ(q1,b,z)={(q1, ε)} δ(q1,a,z0)={(q0,z0)} 5. a)If L is Context free language then prove that there exists PDA M such that L=N(M). b)Explain different types of acceptance of a PDA.Are they equivalent in sense of language acceptance? Justify your answer. 6. Construct a PDA accepting {a n b m a n /m,n>=1} by empty stack. Also construct the corresponding context-free grammar accepting the same set. 7. a) Prove that L is L(M2 ) for some PDA M2 if and only if L is N(M1) for some PDA M1. b)Define deterministic Push Down Automata DPDA. Is it true that DPDA and PDA are equivalent in the sense of language acceptance is concern? Justify Your answer. 8.a) Construct a equivalent grammar G in CNF for the grammar G1 where G1 =({S,A,B},{a,b},{S->bA/aB,A->bAA/aS/a, B->aBB/bS/b},S)
  • 5. Sri vidya college of engineering and technology Lecture notes CS6503 Theory of computation Unit II b)Find the left most and right most derivation corresponding to the tree. 9. a) Find the language generated by a grammar G=({S},{a,b},{S->aSb, S->ab},S) (4) b) Given G=({S,A},{a,b},P,S) where P={S->AaS|S|SS,A->SbA|ba} S-Start symbol. Find the left most and right most derivation of the string w=aabbaaa. Also construct the derivation tree for the string w. c) Define a PDA. Give an Example for a language accepted byPDA by empty stack. 10. G denotes the context-free grammar defined by the following rules. ` S->ASB/ab/SS A->aA/A ,B->bB/A (i)Give a left most derivation of aaabb in G. Draw the associated parse tree. (ii)Give a right most derivation of aaabb in G. Draw the associated parse tree. (iii) Show that G is ambiguous. Explain with steps. (iv) Construct an unambiguous grammar equivalent to G. Explain.