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.