SlideShare a Scribd company logo
1 of 15
Download to read offline
Topic : “Context-free language”
Submitted By:
Punit Dhaked
Harsh Solanki
Submitted to:
Ms. Basu Kalyanwat
TOC Assignment-I
Arya Institute of Engineering Technology and Management
Introduction to Context free language (CLF)
Context-free language are generated by context-free grammars. The set
of all context-free languages is identical to the set of languages
accepted by pushdown automata, and the set of regular languages is a
subset of context-free languages. An inputed language is accepted by a
computational model if it runs through the model and ends in an
accepting final state.
All regular languages are context-free languages, but not all context-
free languages are regular. Most arithmetic expressions are generated
by context-free grammars, and are therefore, context-free languages.
Context-free languages and context-free grammars have applications in
computer science and linguistics such as natural language processing
and computer language design.
• CFG stands for context-free grammar. It is is a formal grammar which
is used to generate all possible patterns of strings in a given formal
language. Context-free grammar G can be defined by four tuples as:
• G = (V, T, P, S)
Context free grammar
Where :
G is the grammar, which consists of a set of the production rule. It is used to
generate the string of a language.
T is the final set of a terminal symbol. It is denoted by lower case letters.
V is the final set of a non-terminal symbol. It is denoted by capital letters.
P is a set of production rules, which is used for replacing non-terminals
symbols(on the left side of the production) in a string with other terminal or
non-terminal symbols(on the right side of the production).
S is the start symbol which is used to derive the string. We can derive the
string by repeatedly replacing a non-terminal by the right-hand side of the
production until all non-terminal have been replaced by terminal symbols.
Closure Properties of Context-freelanguage
• Union
• Concatenation
• Kleene Star
• Reversal operation
• Substitution
• Prefix operation
• Quotient with regular language
• Cycle operation
• Union with regular language
• Intersection with regular language
• Difference with regular language
• Homomorphism
• Inverse Homomorphism
Operations under which CFLs are not closed
• Intersection
• Complement
• Subset
• Superset
• Infinite
• Union Difference
• Symmetric Difference
Union
If L1 and L2 are two context free languages, their union L1 ∪ L2 will also
be context free. For example, L1 = { anbncm | m >= 0 and n >= 0 } and
L2 = { anbmcm | n >= 0 and m >= 0 } L3 = L1 ∪ L2 = { anbncm ∪
anbmcm | n >= 0, m >= 0 } is also context free. L1 says number of a’s
should be equal to number of b’s and L2 says number of b’s should be
equal to number of c’s. Their union says either of two conditions to be
true. So it is also context free language.
Concatenation
If L1 and If L2 are two context free languages, their concatenation L1.L2
will also be context free. For example, L1 = { anbn | n >= 0 } and L2 = {
cmdm | m >= 0 } L3 = L1.L2 = { anbncmdm | m >= 0 and n >= 0} is also
context free. L1 says number of a’s should be equal to number of b’s
and L2 says number of c’s should be equal to number of d’s. Their
concatenation says first number of a’s should be equal to number of
b’s, then number of c’s should be equal to number of d’s. So, we can
create a PDA which will first push for a’s, pop for b’s, push for c’s then
pop for d’s. So it can be accepted by pushdown automata, hence
context free.
If L1 is context free, its Kleene closure L1* will also be
context free. For example, L1 = { anbn | n >= 0 } L1* =
{ anbn | n >= 0 }* is also context free.
Kleene Star Operation
If L1 and If L2 are two context free languages, their intersection L1 ∩ L2
need not be context free. For example, L1 = { anbncm | n >= 0 and m
>= 0 } and L2 = (ambncn | n >= 0 and m >= 0 } L3 = L1 ∩ L2 = { anbncn |
n >= 0 } need not be context free. L1 says number of a’s should be
equal to number of b’s and L2 says number of b’s should be equal to
number of c’s. Their intersection says both conditions need to be true,
but push down automata can compare only two. So it cannot be
accepted by pushdown automata, hence not context free. Similarly,
complementation of context free language L1 which is ∑* – L1, need
not be context free.
Intersection and complementation
The theorem of Pumping Lemma for Context Free Languages is as
follows:Given a Context Free Languages L.There exists an integer p
(pumping length) >= 1 such that for every string STR in L with length of
STR >= p can be written as STR = UVWXY provided:VX is not null /
empty stringlength of VWX <= pfor all i >= 0, UViXYiZ is a part of L.Note
we are pumping two substrings V and Y. In Pumping Lemma for Regular
Languages, we were pumping only one substring Y.Following image will
help you understand this theorem:
Pumping Lemma for Context Free Languages
Pushdown Automata can be used to recognize Context Free Languages
(CFL).Moreover, Pushdown Automata can be used to prove that all
Regular Languages are Context Free Languages. Decidable properties of
Context Free Language:
• Decidable for Membership
• Decidable for Emptiness
• Decidable for finiteness
Based on Deterministic properties, Context Free Language can be divided
as:
• Deterministic Context Free Language
• Non Deterministic Context Free Language
How to recognize Context Free Language?
Example 1
• Question : Consider the language L1,L2,L3 as given below. L1 = { ambn | m, n >= 0
} L2 = { anbn | n >= 0 } L3 = { anbncn | n >= 0 } Which of the following statements
is NOT TRUE? A. Push Down Automata(PDA)can be used to recognize L1 and L2
B. L1 is a regular language C. All the three languages are contextfree D. Turing
machine can be used to recognize all the three languages
• Solution : Option (A) says PDA can be used to recognize L1 and L2. L1 contains all
strings with any no. Of a followed by any no. Of b. So, it can be accepted by PDA.
L2 contains strings with n no. Of a’s followed by n no. Of b’s. It can also be
accepted by PDA. So, option (A) is correct. Option (B) says that L1 is regular. It is
true as regular expression for L1 is a*b*. Option (C) says L1, L2 and L3 are context
free. L3 languages contains all strings with n no. Of a’s followed by n no. Of b’s
followed by n no. Of c’s. But it can’t be accepted by PDA. So option ( C) is not
correct. Option (D) is correct as Turing machine can be used to recognize all the
three languages.
Example 2
• Question : The language L = { 0i12i | i ≥ 0 } over the alphabet {0, 1, 2}
is : A. Not recursive B. Is recursive and deterministic CFL C. Is regular
D. Is CFL bot not deterministic CFL.
• Solution : The above language is deterministic CFL as for 0’s, we can
push 0 on stack and for 2’s we can pop corresponding 0’s. As there is
no ambiguity which moves to take, it is deterministic. So, correct
option is (B). As CFL is subset of recursive, it is recursive as well.
Thank You

More Related Content

Similar to Presentation (5).pdf

Theory of computing
Theory of computingTheory of computing
Theory of computing
Ranjan Kumar
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
Jagjit Wilku
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
prasadmvreddy
 
Final formal languages
Final formal languagesFinal formal languages
Final formal languages
Megha Khanna
 

Similar to Presentation (5).pdf (20)

Theory of Computation Lecture Notes
Theory of Computation Lecture NotesTheory of Computation Lecture Notes
Theory of Computation Lecture Notes
 
flatPresentation.pdf
flatPresentation.pdfflatPresentation.pdf
flatPresentation.pdf
 
Normal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.pptNormal-forms-for-Context-Free-Grammars.ppt
Normal-forms-for-Context-Free-Grammars.ppt
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
Automata
AutomataAutomata
Automata
 
Automata
AutomataAutomata
Automata
 
Module 1 TOC.pptx
Module 1 TOC.pptxModule 1 TOC.pptx
Module 1 TOC.pptx
 
Unit ii
Unit iiUnit ii
Unit ii
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
 
Lecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdfLecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdf
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 
Chomsky hierarchy
Chomsky hierarchyChomsky hierarchy
Chomsky hierarchy
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
 
9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx
 
Final formal languages
Final formal languagesFinal formal languages
Final formal languages
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free Grammer
 
RegularLanguage.pptx
RegularLanguage.pptxRegularLanguage.pptx
RegularLanguage.pptx
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
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
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 

Presentation (5).pdf

  • 1. Topic : “Context-free language” Submitted By: Punit Dhaked Harsh Solanki Submitted to: Ms. Basu Kalyanwat TOC Assignment-I Arya Institute of Engineering Technology and Management
  • 2. Introduction to Context free language (CLF) Context-free language are generated by context-free grammars. The set of all context-free languages is identical to the set of languages accepted by pushdown automata, and the set of regular languages is a subset of context-free languages. An inputed language is accepted by a computational model if it runs through the model and ends in an accepting final state. All regular languages are context-free languages, but not all context- free languages are regular. Most arithmetic expressions are generated by context-free grammars, and are therefore, context-free languages. Context-free languages and context-free grammars have applications in computer science and linguistics such as natural language processing and computer language design.
  • 3. • CFG stands for context-free grammar. It is is a formal grammar which is used to generate all possible patterns of strings in a given formal language. Context-free grammar G can be defined by four tuples as: • G = (V, T, P, S) Context free grammar
  • 4. Where : G is the grammar, which consists of a set of the production rule. It is used to generate the string of a language. T is the final set of a terminal symbol. It is denoted by lower case letters. V is the final set of a non-terminal symbol. It is denoted by capital letters. P is a set of production rules, which is used for replacing non-terminals symbols(on the left side of the production) in a string with other terminal or non-terminal symbols(on the right side of the production). S is the start symbol which is used to derive the string. We can derive the string by repeatedly replacing a non-terminal by the right-hand side of the production until all non-terminal have been replaced by terminal symbols.
  • 5. Closure Properties of Context-freelanguage • Union • Concatenation • Kleene Star • Reversal operation • Substitution • Prefix operation • Quotient with regular language • Cycle operation • Union with regular language • Intersection with regular language • Difference with regular language • Homomorphism • Inverse Homomorphism
  • 6. Operations under which CFLs are not closed • Intersection • Complement • Subset • Superset • Infinite • Union Difference • Symmetric Difference
  • 7. Union If L1 and L2 are two context free languages, their union L1 ∪ L2 will also be context free. For example, L1 = { anbncm | m >= 0 and n >= 0 } and L2 = { anbmcm | n >= 0 and m >= 0 } L3 = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also context free. L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their union says either of two conditions to be true. So it is also context free language.
  • 8. Concatenation If L1 and If L2 are two context free languages, their concatenation L1.L2 will also be context free. For example, L1 = { anbn | n >= 0 } and L2 = { cmdm | m >= 0 } L3 = L1.L2 = { anbncmdm | m >= 0 and n >= 0} is also context free. L1 says number of a’s should be equal to number of b’s and L2 says number of c’s should be equal to number of d’s. Their concatenation says first number of a’s should be equal to number of b’s, then number of c’s should be equal to number of d’s. So, we can create a PDA which will first push for a’s, pop for b’s, push for c’s then pop for d’s. So it can be accepted by pushdown automata, hence context free.
  • 9. If L1 is context free, its Kleene closure L1* will also be context free. For example, L1 = { anbn | n >= 0 } L1* = { anbn | n >= 0 }* is also context free. Kleene Star Operation
  • 10. If L1 and If L2 are two context free languages, their intersection L1 ∩ L2 need not be context free. For example, L1 = { anbncm | n >= 0 and m >= 0 } and L2 = (ambncn | n >= 0 and m >= 0 } L3 = L1 ∩ L2 = { anbncn | n >= 0 } need not be context free. L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their intersection says both conditions need to be true, but push down automata can compare only two. So it cannot be accepted by pushdown automata, hence not context free. Similarly, complementation of context free language L1 which is ∑* – L1, need not be context free. Intersection and complementation
  • 11. The theorem of Pumping Lemma for Context Free Languages is as follows:Given a Context Free Languages L.There exists an integer p (pumping length) >= 1 such that for every string STR in L with length of STR >= p can be written as STR = UVWXY provided:VX is not null / empty stringlength of VWX <= pfor all i >= 0, UViXYiZ is a part of L.Note we are pumping two substrings V and Y. In Pumping Lemma for Regular Languages, we were pumping only one substring Y.Following image will help you understand this theorem: Pumping Lemma for Context Free Languages
  • 12. Pushdown Automata can be used to recognize Context Free Languages (CFL).Moreover, Pushdown Automata can be used to prove that all Regular Languages are Context Free Languages. Decidable properties of Context Free Language: • Decidable for Membership • Decidable for Emptiness • Decidable for finiteness Based on Deterministic properties, Context Free Language can be divided as: • Deterministic Context Free Language • Non Deterministic Context Free Language How to recognize Context Free Language?
  • 13. Example 1 • Question : Consider the language L1,L2,L3 as given below. L1 = { ambn | m, n >= 0 } L2 = { anbn | n >= 0 } L3 = { anbncn | n >= 0 } Which of the following statements is NOT TRUE? A. Push Down Automata(PDA)can be used to recognize L1 and L2 B. L1 is a regular language C. All the three languages are contextfree D. Turing machine can be used to recognize all the three languages • Solution : Option (A) says PDA can be used to recognize L1 and L2. L1 contains all strings with any no. Of a followed by any no. Of b. So, it can be accepted by PDA. L2 contains strings with n no. Of a’s followed by n no. Of b’s. It can also be accepted by PDA. So, option (A) is correct. Option (B) says that L1 is regular. It is true as regular expression for L1 is a*b*. Option (C) says L1, L2 and L3 are context free. L3 languages contains all strings with n no. Of a’s followed by n no. Of b’s followed by n no. Of c’s. But it can’t be accepted by PDA. So option ( C) is not correct. Option (D) is correct as Turing machine can be used to recognize all the three languages.
  • 14. Example 2 • Question : The language L = { 0i12i | i ≥ 0 } over the alphabet {0, 1, 2} is : A. Not recursive B. Is recursive and deterministic CFL C. Is regular D. Is CFL bot not deterministic CFL. • Solution : The above language is deterministic CFL as for 0’s, we can push 0 on stack and for 2’s we can pop corresponding 0’s. As there is no ambiguity which moves to take, it is deterministic. So, correct option is (B). As CFL is subset of recursive, it is recursive as well.