0% found this document useful (0 votes)
22 views11 pages

Chapter-2.1 CFG and Derivations

The document outlines the course objectives and outcomes for a Theory of Computation class, focusing on formal languages, grammars, and automata theory. It includes detailed explanations of context-free grammars, context-sensitive languages, and Turing machines, along with examples and practice questions. References for further study are also provided.

Uploaded by

Sajal Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Chapter-2.1 CFG and Derivations

The document outlines the course objectives and outcomes for a Theory of Computation class, focusing on formal languages, grammars, and automata theory. It includes detailed explanations of context-free grammars, context-sensitive languages, and Turing machines, along with examples and practice questions. References for further study are also provided.

Uploaded by

Sajal Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

APEX INSTITUTE OF TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Theory of Computation(22CST-390)
Faculty: Rosevir Singh(E16685)

Context Free Grammar DISCOVER . LEARN . EMPOWER

1
Theory Of Computation: Course Objectives

COURSE OBJECTIVES
The Course aims to:
1.Demonstrate Knowledge of basic mathematical models of computation and describe how they relate to
formal languages.
2.Develop Understanding of what are limitations on what computers can do and learn examples of
unsolvable problems.
3.Teach that certain problems do not admit efficient algorithms and Identify such problems.

By: Rosevir Singh 2


COURSE OUTCOMES
On completion of this course, the students shall be able to:-

Describe fundamental concepts of formal languages, grammars, and automata theory,


CO1
including alphabets, languages, grammars, and the Chomsky hierarchy.
Understand the structure and behavior of finite automata, regular languages, context-
CO2 free languages, context-sensitive languages, and Turing machines, and demonstrate
their equivalences and applications.
Apply properties, theorems (Kleene's theorem, pumping lemma, Myhill-Nerode
CO3 theorem), and algorithms for minimization, parsing, and decision problems in
automata and formal language theory.
Analyze the computational power and limitations of different language classes and
CO4 automata, including undecidability and complexity distinctions between P, NP, and
NP-complete problems.
Evaluate computational problems using reductions, and construct proofs for
CO5 undecidability and complexity, leveraging concepts such as the Church-Turing thesis,
Cook’s theorem, and Rice's theorem.

3
Unit-2

• CONTEXT-FREE LANGUAGES AND PUSHDOWN AUTOMATA: Context-free


grammars (CFG) and languages (CFL), Chomsky and Greibach normal forms,
nondeterministic pushdown automata (PDA) and equivalence with CFG, parse
trees, ambiguity in CFG, pumping lemma for context-free languages,
deterministic pushdown automata, closure properties of CFLs.

• CONTEXT-SENSITIVE LANGUAGES Context-sensitive grammars (CSG) and


languages, linear bounded automata and equivalence with CSG.

• TURING MACHINES The basic model for Turing machines (TM), Turing
recognizable(recursively enumerable) and Turing-decidable (recursive) languages
and their closure properties, variants of Turing machines, nondeterministic TMs
and equivalence with deterministic TMs, unrestricted grammars and equivalence
with Turing machines, TMs as enumerators.

4
Context free Grammar
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)
•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
• Example 1: Construct the CFG for the language having any number of a's over the set ∑=
{a}.
• Solution:
• As we know the regular expression for the above language is
1.r.e. = a*
• Production rule for the Regular expression is as follows:
1.S → aS rule 1
2.S → ε rule 2
Now if we want to derive a string "aaaaaa", we can start with start symbols.
1. S
2.aS
3.aaS rule 1
4.aaaS rule 1
5.aaaaS rule 1
6.aaaaaS rule 1
7.aaaaaaS rule 1
8.aaaaaaε rule 2
9.aaaaaa
The r.e. = a* can generate a set of string {ε, a, aa, aaa,.....}. We can have a null string because S
is a start symbol and rule 2 gives S → ε. 6

Example 2:
Construct a CFG for the regular expression (0+1)*
• Solution:
The CFG can be given by,
1.Production rule (P):
2.S → 0S | 1S
3.S → ε
• The rules are in the combination of 0's and 1's with the start symbol.
Since (0+1)* indicates {ε, 0, 1, 01, 10, 00, 11, ....}. In this set, ε is a
string, so in the rule, we can set the rule S → ε.
• Example 3:
Construct a CFG for a language L = {wcwR | where w € (a, b)*}.
Solution:
• The string that can be generated for a given language is {aacaa, bcb, abcba, bacab, abbcbba, ....}
• The grammar could be:
1. S → aSa rule 1
2. S → bSb rule 2
3. S → c rule 3
• Now if we want to derive a string "abbcbba", we can start with start symbols.
1. S → aSa
2. S → abSba from rule 2
3. S → abbSbba from rule 2
4. S → abbcbba from rule 3
• Thus any of this kind of string can be derived from the given production rules.
• Example 4:
Construct a CFG for the language L = a nb2n where n>=1.
Solution:
• The string that can be generated for a given language is {abb, aabbbb, aaabbbbbb....}.
• The grammar could be:
1. S → aSbb | abb

• Now if we want to derive a string "aabbbb", we can start with start symbols.
1. S → aSbb

2. S → aabbbb
8
Practice Questions:

Ques1:Explain the concept of Context Free Grammar.

Ques2:Construct a CFG for a language L = {wcwR | where w € (a, b)*}.

9
References

• Introduction to the Theory of Computation, Michael Sipser.


• https://www.geeksforgeeks.org/what-is-context-free-grammar/
• https://en.wikipedia.org/wiki/Context-free_grammar
• https://www.javatpoint.com/context-free-grammar
• https://www.youtube.com/watch?v=5_tfVe7ED3g
• https://www.youtube.com/watch?v=nyjB5xW0tQc
THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy