TOC in 8 hours (1)
TOC in 8 hours (1)
• Chapter-1 (Basic Concepts and Automata Theory): Introduction to Theory of Computation- Automata, Computability and
Complexity, Alphabet, Symbol, String, Formal Languages, Deterministic Finite Automaton (DFA)- Definition, Representation,
Acceptability of a String and Language, Non Deterministic Finite Automaton (NFA), Equivalence of DFA and NFA, NFA with ε-
Transition, Equivalence of NFA’s with and without ε-Transition, Finite Automata with output- Moore Machine, Mealy
Machine, Equivalence of Moore and Mealy Machine, Minimization of Finite Automata.
• Chapter-2 (Regular Expressions and Languages): Regular Expressions, Transition Graph, Kleen’s Theorem, Finite Automata
and Regular Expression- Arden’s theorem, Algebraic Method Using Arden’s Theorem, Regular and Non-Regular Languages-
Closure properties of Regular Languages, Pigeonhole Principle, Pumping Lemma, Application of Pumping Lemma,
Decidability- Decision properties, Finite Automata and Regular Languages
• Chapter-3 (Regular and Non-Regular Grammars): Context Free Grammar(CFG)-Definition, Derivations, Languages, Derivation
Trees and Ambiguity, Regular Grammars-Right Linear and Left Linear grammars, Conversion of FA into CFG and Regular
grammar into FA, Simplification of CFG, Normal Forms- Chomsky Normal Form(CNF), Greibach Normal Form (GNF), Chomsky
Hierarchy, Programming problems based on the properties of CFGs.
• Chapter-4 (Push Down Automata and Properties of Context Free Languages): Nondeterministic Pushdown Automata
(NPDA)- Definition, Moves, A Language Accepted by NPDA, Deterministic Pushdown Automata(DPDA) and Deterministic
Context free Languages(DCFL), Pushdown Automata for Context Free Languages, Context Free grammars for Pushdown
Automata, Two stack Pushdown Automata, Pumping Lemma for CFL, Closure properties of CFL, Decision Problems of CFL,
Programming problems based on the properties of CFLs.
• Chapter-5 (Turing Machines and Recursive Function Theory): Basic Turing Machine Model, Representation of Turing
Machines, Language Acceptability of Turing Machines, Techniques for Turing Machine Construction, Modifications of Turing
Machine, Turing Machine as Computer of Integer Functions, Universal Turing machine, Linear Bounded Automata, Church’s
Thesis, Recursive and Rece Problem, Introduction to
• Chapter-1 (Basic Concepts and Automata Theory):
Introduction to Theory of Computation- Automata,
Computability and Complexity, Alphabet, Symbol, String,
Formal Languages, Deterministic Finite Automaton (DFA)-
Definition, Representation, Acceptability of a String and
Language, Non Deterministic Finite Automaton (NFA),
Equivalence of DFA and NFA, NFA with ε-Transition,
Equivalence of NFA’s with and without ε-Transition, Finite
Automata with output- Moore Machine, Mealy Machine,
Equivalence of Moore and Mealy Machine, Minimization
of Finite Automata.
http://www.knowledgegate.in/gate
INTRODUCTION TO THEORY OF
COMPUTATIONS
http://www.knowledgegate.in/gate
• As word suggests ‘TOC’ is the study of 'mathematical' machines or systems
called automata.
• Theory of computation can be considered as the study of all kinds of
computational model in the field of computer science and it also considers how
efficiently the problem can be solved (but not is depth).
http://www.knowledgegate.in/gate
PROBLEM
• Now a day’s machines (digital, analog, mechanical) play a very
important role in the development of human, we need some
mechanism (language) to communicate with the machines.
http://www.knowledgegate.in/gate
SOLUTION
• We need a language for communication with machines. But we do not require
natural languages to communicate with the machines, as natural languages are
very complex and machine interaction require very fewer complex languages
compare to natural languages.
http://www.knowledgegate.in/gate
• Languages can be of two types formal languages and informal languages, here
in this subject we will only discuss formal languages.
• Dictionary defines the term informally as ‘a system suitable for the expression of
certain ideas, facts or concepts including a set of symbols for their manipulation’.
http://www.knowledgegate.in/gate
METHODS TO DEFINE LANGUAGE
http://www.knowledgegate.in/gate
• STRING - It is a finite sequence of symbols (which are the
member of set alphabet). E.g. Σ = {a, b} String- aabb, aa, b,
so on. (in English we called them as words).
http://www.knowledgegate.in/gate
• LANGUAGE - A language is defined as a set of strings. (in natural
language (set of words(predefined) and grammar) we apply this
model from words to sentence).
• In the next level we consider programs as a string and programming
constructs/tokens like int, floats as letters/symbols.
http://www.knowledgegate.in/gate
• Similarly, in our system we have finite number of symbols/letters but using
those letters we can generate infinite strings/words.
• So, we may have languages that have infinite number of words, so it is not
possible for us to list them, we have to use some framework, which can
somehow represent the same language. There are mainly two methods to
represent a language
• by a grammar that generates a language [RG generate RL]
http://www.knowledgegate.in/gate
• The Theory of Formal Languages is a branch of theoretical computer science
that deals with the study of formal languages and their properties.
• The theory of formal languages includes the study of formal grammars, which
are used to define the syntax of formal languages, and automata theory, which
deals with the study of abstract machines used to recognize, generate, or process
formal languages. Some of the key concepts studied in the theory of formal
languages include regular languages, context-free languages, context-sensitive
languages, recursively enumerable languages, and the Chomsky hierarchy.
• The theory of formal languages has important applications in areas such as
compilers, parsers, and other software engineering tools, as well as in the
design of programming languages and the study of natural language processing.
http://www.knowledgegate.in/gate
Q if ∑ = {a, b} then, find the following?
0
∑ =
1
∑ =
2
∑ =
3
∑ =
http://www.knowledgegate.in/gate
K
• ∑ is the set of all the strings from the alphabet ∑ of length exactly K.
• A Finite automaton is a model that has a finite set of states (represented in the figure by
circles) and its control moves from one state to another state in response to external
inputs (represented by arrows).
2. Mealy machine
http://www.knowledgegate.in/gate
• In general, this type of automata is characterized by machine having no
temporary storage, as it is severely limited in its capacity to remember
things during the computation.
• Only finite amount of information can be in the control unit by placing the unit
into a specific state but since the number of states is finite, a finite automaton
can only deal with situation in which the information to be stored at any time is
strictly bounded.
http://www.knowledgegate.in/gate
DETERMINISTIC FINITE AUTOMATA
where:
• δ is a transition function, ( δ: Q × Σ 🡪 Q)
http://www.knowledgegate.in/gate
DFA Designing
DFA.
• The best knowledge about DFA can be only understood by designing a
number of DFA, by doing so we will first understand the process of
DFA designing and secondly, we will understand Regular Language.
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b}, where every accepted string ‘w’ starts with
substring s = ‘abb’
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b}. where every accepted string ‘w’ ends with
substring ‘s = bab’ ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b}. where every accepted string ‘w’ contains
sub string s= ‘aba’?
http://www.knowledgegate.in/gate
• The various components of the block diagram
are explained as follows:
http://www.knowledgegate.in/gate
Representation
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end
with same symbol?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end
with different symbol?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like
w=SX. S=aaa/bbb?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like
w=XS. S=aaa/bbb?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like
w=XSX. S=aaa/bbb?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑
= {a, b}, such that every string ‘w’ accepted must be like
i) |w| = 3
ii) |w|<=3
iii) |w|>=3
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a, b},
s
such that every string accepted must contain exactly two a’ , |w|a=2 ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at least two a’s,
|w|a >= 2 ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain at most two a’s,
|w|a <= 2 ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string ‘w’ accepted must be like
i) |w| = 0(mod 3) ii) |w|=1(mod 4)
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain
i) number of a is, |w|a = 0(mod 2)
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 2th from left end is always a ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b} such that for every accepted string 2nd from right end is always b ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must contain be like,
no of a = 0(mod 2) || no of b = 0(mod 2) ?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ =
{0,1}, such that every string ‘w’ which is accepted has a decimal
equivalent 0(mod 3) ?
http://www.knowledgegate.in/gate
COMPLIMENT OF DFA
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}, such that every string accepted must not contain a substring ’aaa’?
http://www.knowledgegate.in/gate
NON DETEMINISTIC FINITE AUTOMATA
• Non determinism means choice of move for an automaton. So rather than prescribing
a unique move in each situation, we allow a set of possible moves.
• Non deterministic machine are only theoretical machine i.e. in the first place they are not
implementable and neither we want to implement them, the only reason we study non-
determinism is because they are easy to design and easily be converted into
deterministic machine.
http://www.knowledgegate.in/gate
FORMAL DESCRIPTION OF NDFA
• A Non-Deterministic finite automaton (NDFA) is a 5-tuple
(Q,Σ,δ,S,F) where:
• Q is a finite and non-empty set of states
• δ is a transition function δ: Q × Σ 🡪 2Q
http://www.knowledgegate.in/gate
Some points to remember
• Every DFA is also an NFA.
• Every NFA can be translated to an equivalent DFA, so their language accepting capability
is same.
• NFAs like DFA’s only recognize regular languages.
• It need not to be a complete system. There can be a state that doesn’t have any transition
on some input symbol.
• It is possible that a single state led to multiple transition on same input to different states.
• NOTE- A null transition is also possible for NFA, such special NFA are called Null-NFA. We
will discuss it later.
http://www.knowledgegate.in/gate
PROPERTIES OF NFA
• i) Accepting power of NDFA= Accepting power of DFA.
• ii) NDFA is a theoretical engine and is not implementable, but it is very easy to
design compare to DFA.
• iv) NDFA will respond for only valid strings and no need to respond for invalid
strings. (it is a Incomplete system)
http://www.knowledgegate.in/gate
ACCEPTANCE BY NDFA
• Let ‘w’ be any string defined over the alphabet Σ, corresponding to w, there
can be multiple transitions for NFA starting from initial state, if there exist at
least one transition for which we start at the initial state and ends in any One of
the final state, then the string ‘w’ is said to be accepted by the
non-deterministic finite automata, otherwise not.
http://www.knowledgegate.in/gate
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}.
where every accepted string ‘w’ ends with substring ‘s’, Where s = ‘bab’?
http://www.knowledgegate.in/gate
Q Design a minimal DFA that accepts all strings over the alphabet ∑ = {a,
b}. where every accepted string ‘w’ contains sub string s, Where s = ’aba’ ?
http://www.knowledgegate.in/gate
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
such that every accepted string start and end with same symbol ?
http://www.knowledgegate.in/gate
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b} such
that every accepted string start and end with different symbol ?
http://www.knowledgegate.in/gate
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=SX , Where s = aaa/bbb
http://www.knowledgegate.in/gate
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
{a, b} such that every accepted string w, is like w=XS , Where s = aaa/bbb
http://www.knowledgegate.in/gate
Q Design a minimal NDFA that accepts all strings over the alphabet ∑ =
aaa/bbb ?
http://www.knowledgegate.in/gate
Q Design a NDFA that accepts all strings over the alphabet ∑ = {a, b}
rd
such that for every accepted string 3 from right end is always a ?
http://www.knowledgegate.in/gate
NFA and DFA Equivalence
• In this topic we will be learning about the equivalence of NFA and DFA and how
an NFA can be converted to equivalent DFA. Let us take an example and
understand the conversion.
• Since every NFA and DFA has equal power that means, for every language if a
NFA is possible, then DFA is also possible.
• So, every NFA can be converted to DFA.
• The process of conversion of an NFA into a DFA is called Subset Construction.
http://www.knowledgegate.in/gate
• If NFA have ‘n’ states which is converted into DFA which
‘m’ states than the relationship between n and m will be
n
• 1<= m <= 2
http://www.knowledgegate.in/gate
Procedure for Conversion
• There lies a fixed algorithm for the NFA and DFA conversion. Following
things must be considered
• Initial state will always remain same.
• Start the construction of δ’ with the initial state & continue for every
new state that comes under the input column and terminate the process
whenever no new state appears under the input column.
• Every subset of states that contain the final state of the NFA is a final state in
the resulting DFA.
δ’(q q q q q δ
a) = ⋃i"𝑛%& ( q a)
• 0, 1, 2, 3--------, n-1, i,
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
DFA (Deterministic Finite NDFA
Aspect Automata) (Nondeterministic
Finite Automata)
State Transition On each input symbol, Can transition to multiple
transitions to exactly one states or none on the same
state. input symbol.
te state.
NFA WITH EPSILON MOVES (€-NFA)
• An automaton that consist of null transitions is called a Null- NFA i.e. we allow a transition
on null means empty string.
• €-NFA is a 5-tuple (Q,Σ,δ,S,F) where:
http://www.knowledgegate.in/gate
NULL-CLOSURE
• Null closure of a set Q is defined as a set of all the states, which are at zero distance
from the state Q. A set of all the states, that can be reached from the state and along a
null- transition.
• €-Closure(qi)- The set of all the states which are at zero distance from the state qi is
called €-closure(qi). Or the set of all the states that can be reached from the state
qi along € labelled transition path, is known as €-closure(qi).
http://www.knowledgegate.in/gate
• Every state is at zero distance to itself.
• In NFA or DFA, distance between two states is always 1, because there
could be no null transitions.
• The Null closure Q is always a non-empty and finite state, because
every state’s null closure is that state only.
• €-closure(Φ) = Φ
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
• Let us check for ẟ(q0, a) = ε-Closure [ẟ[ε-Closure(q0), a]]
• first, we find ε-Closure of q0: {q0, q1, q2}
• Now check transition of all three states on input symbol a we get: q0
• After that we again calculate the ε-Closure of the above result q0, we get the result as: {q0, q1,
q2}
• Similarly, we will check it for every state.
• All those states will be considered as a final state in which we have q2(final state in initial
ε- NFA) in there ε-Closure, i.e. all states will be final in this case.
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
Moore and Mealy Machine
• Both moore and mealy machine are special case of DFA
H M ea l y E d w ard F M o o re
h ttp : / /www.knowledgeg a t e . i n /g a t e
Moore Machine
A Moore machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where
• Q is a finite set of states:
• ∑ is the input alphabet:
• Δ is the output alphabet.
• δ is the transition function Q x ∑ into Q
• λ is the output function mapping Q into Δ and
• q0 is the initial state.
http://www.knowledgegate.in/gate
Examples: The below table shows the transition table of a Moore Machine.
http://www.knowledgegate.in/gate
• In moore machine for every state output is associated.
• If the length of i/p string is n, then length of o/p string will be n+1
http://www.knowledgegate.in/gate
Q construct a Moore machine take all the string of a’s and b’s as i/p and counts
the no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
http://www.knowledgegate.in/gate
Q construct a Moore machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
http://www.knowledgegate.in/gate
Mealy Machine
• Mealy machine is a six-tuple (Q, ∑, Δ, δ, λ, q0), where all the symbols except
λ have the same meaning as in the Moore machine. λ is the output function
mapping Q x ∑ into Δ.
http://www.knowledgegate.in/gate
Example: The below table shows the transition table of a Mealy Machine.
http://www.knowledgegate.in/gate
• If the length of i/p string is n, then length of o/p string will be n
http://www.knowledgegate.in/gate
Q construct a Mealy machine take all the string of a’s and b’s as i/p and counts
the no of occurrence of sub-string ‘ab’ in terms of 1, ∑ = {a, b}, Δ = {0, 1}?
http://www.knowledgegate.in/gate
Q construct a Mealy machine where ∑ = {0, 1}, Δ = {a, b, c}, machine should give
o/p a, if the i/p string ends with 10, b if i/p string ends with 11, c otherwise?
http://www.knowledgegate.in/gate
CONVERSION OF MOORE TO MEALY MACHINE
• Let us take an example to understand the conversion:
htntepc:e/s/sawry w.knowledgegacthea.ninge/sg.
w. ate
MINIMIZATION OF FINITE AUTOMATA
• The process of elimination of states whose presence or absence doesn’t affect the
language accepting capability of deterministic Finite Automata is called minimization of
automata and the result is minimal deterministic finite automata or commonly called
as minimal finite automata as MFA.
http://www.knowledgegate.in/gate
• It is sometimes difficult to design a minimal DFA directly so, a better approach is to first
design the DFA and then minimize it.
• Based on productivity, the states of DFA can be mainly classified in two types-
• NON- PRODUCTIVE STATES- These states don’t any add anything to the language
accepting power to the machine.
http://www.knowledgegate.in/gate
NON- PRODUCTIVE STATES- These states don’t add anything to the language
accepting power to the machine. They can further be divided into three types-
• Dead State
• Unreachable Sate
• Equal State
http://www.knowledgegate.in/gate
• Dead State- It is basically created to make the system complete, can be defined as
a state from which there is no transition possible to the final state.
• In a DFA there can be more than one dead state but logically always one dead state is
sufficient to complete the functionality.
http://www.knowledgegate.in/gate
• Unreachable Sate- It is that state which cannot be reached starting
from initial state by parsing any input string.
http://www.knowledgegate.in/gate
• Equal State-These are those states that behave in same manner on each and
every input string. That is for any string w where w ∈ Σ either both of the
*
states will go to final state or both will go to non-final state. (remember the
example of an equal state DFA).
• More formally, two states ql and q2 are equivalent (denoted by q1≅ q2) if both δ
(q1, x) and δ (q2, x) are final states or both of them are non-final states for all x ∈
∑*. If q1 and q2 are k-equivalent for all k ≥ 0, then they are k-equivalent.
http://www.knowledgegate.in/gate
Procedure of Minimization
• For this first of all, group all the non-final states in one set and all final states in
another set.
• Now, on both the sets, individually check, whether any of the underlying elements (states)
of that particular set are behaving in the same way, that is are they having same
transition(to same set) on each input alphabet.
• if the answer is yes, then these two states are equal, otherwise not.
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
• Chapter-2 (Regular Expressions and Languages):
Regular Expressions, Transition Graph, Kleen’s
Theorem, Finite Automata and Regular Expression-
Arden’s theorem, Algebraic Method Using Arden’s
Theorem, Regular and Non-Regular Languages-
Closure properties of Regular Languages,
Pigeonhole Principle, Pumping Lemma, Application
of Pumping Lemma, Decidability- Decision
properties, Finite Automata and Regular Languages
http://www.knowledgegate.in/gate
Regular Expressions
• One way of describing regular language is via the notation of regular expression. An
expression of strings which represents regular language is called regular expression. The
regular expressions are useful for representing certain sets of strings(Language) in an algebraic
fashion.
• We give a formal recursive definition of regular expressions over ∑ as follows:
• Any terminal symbol (i.e. an element of ∑), ∈ and Φ are regular expressions
(Primitive regular expressions).
• A regular expression is valid iff it can be derived from a primitive regular expression by
a finite number of applications of operators.
http://www.knowledgegate.in/gate
Regular Language:- Any set(language) represented by a regular
expression is called a Regular language. If for example, a, b ∈ ∑, then
• R = a denotes the L = {a}
• R = a* denotes the set {∈, a, aa, aaa, ...} known as Kleene closure.
+
• R = a Positive closure {a, aa, aaa…}
regular expression.
http://www.knowledgegate.in/gate
Operator Precedence
• The precedence order to solve is
• ()Bracket
• * (Kleene Closure)
• + Positive Closure
• Concatenation
• Union
http://www.knowledgegate.in/gate
IDENTITIES FOR Regular Expression
• Two regular expression are said to be equal if they generate same language.
• r1 = a*
• r2 = a* + (aa)*
http://www.knowledgegate.in/gate
हमारk language बताओ
1. R={a}
2. R={a + b}
3. R={a + b + c}
http://www.knowledgegate.in/gate
1. R={a.b}
2. R={a.b + a}b
http://www.knowledgegate.in/gate
Q Design a regular expression that represent a language ‘L’, where L={a}
over the alphabet ∑={a}.
http://www.knowledgegate.in/gate
Q design a regular expression that represent all strings over the alphabet
∑ = {a, b}, where every accepted string ‘w’ starts with substring s = ‘abb’
http://www.knowledgegate.in/gate
Q design a regular expression that represent all strings over the alphabet
∑ = {a, b}. where every accepted string ‘w’ ends with substring s = ‘bab’?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}. where every accepted string ‘w’ contains sub string s
= ‘aba’ ?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with a.
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with
same symbol?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string start and end with
different symbol ?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=SX S =
‘aaa/bbb’ ?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=XS. S =
‘aaa/bbb’ ?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that every accepted string w, is like w=XSX. S =
aaa/bbb ?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b}, such that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that for every accepted string 2nd from left end
is always b.
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑ = {a, b} such that for every accepted string 4th from right end
is always a.
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 0(mod 3)?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W| = 3(mod 4)?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W|a = 0(mod 3)?
http://www.knowledgegate.in/gate
Q Design a regular expression that represent all strings over the
alphabet ∑= {a, b}, such that every string ‘w’ where |W|b = 2(mod 3)?
http://www.knowledgegate.in/gate
Algebraic Properties of regular expression
• Closure Property - Regular expressions satisfy closure property with respect
to Union, Concatenation and kleene closure. If R1 and R2 are regular
expression then the following will also be regular expression.
r1 + r2
r1.r2
r1*
+
1
http://www.knowledgegate.in/gate
• Associative Property- Regular expression satisfy associative property with
respect to union and intersection
http://www.knowledgegate.in/gate
• Identity Property- The identity property is satisfied as follows-
r. =r
r+ =r
http://www.knowledgegate.in/gate
• Commutative Property- Regular expressions are commutative with
respect to union but not with respect to concatenation.
r1+ r2 r2+ r1
r1. r2 r2. r1
http://www.knowledgegate.in/gate
• Distributive Property-Regular expression satisfy this property as follows-
r1(r2+r3) r1r2+r1r3
(r1+r2) r3 r1r3+r2r3
ate
• Idempotent Property-regular expressions satisfies idempotent
property with respect to union but not with respect to concatenation.
r1+r1 r1
r1. r1 r1
http://www.knowledgegate.in/gate
Conversion from Finite Automata to regular expression
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
Conversion from regular
i) R* expression in Finite Automata
ii) (R1.R2)*
iii) (R1+R2)*
http://www.knowledgegate.in/gate
iv) (R1*R2.R3*)
v) R = a*b(ab)*
vi) R = (a + ba)*ab*
http://www.knowledgegate.in/gate
vii) R = (aa + aaa)*
viii) R = (a + aaaaa)*
http://www.knowledgegate.in/gate
1. 0 * 10 * 10 *
2. ((ab)* + c*)*
4. 0*(10 * 1*)*0*
http://www.knowledgegate.in/gate
1. a*b(b * + aa*b)*
2. ((11*0+0)(0 + 1)*0*1*)
http://www.knowledgegate.in/gate
EQUIVALENCE BETWEEN Regular Expression AND FINITE AUTOMATA
http://www.knowledgegate.in/gate
Q Consider a DFA and convert it into regular expression using Arden’s theorem?
δ(A, a) = A
δ(A, b) = B
δ(B, a) = B
δ(B, b) = B
• For, every individual state of the DFA, write an expression for every
incoming and outgoing input alphabet.
• Apply Arden’s theorem as follows-
• If P is free from NULL, then equation R=Q+RP has unique solution, R=QP*
δ(A, b) = A
δ(A, b) = B
δ(B, a) = C
δ(C, b) = C
multiple moves).
• Can have string as a input to transition from one state to another.
http://www.knowledgegate.in/gate
Kleene’s Theorem
• The theorem has two main parts:
• For any given regular expression, there is an equivalent finite automaton
(either deterministic or non-deterministic) that recognizes the same
language.
• For any finite automaton, there is an equivalent regular expression that
generates the same language.
http://www.knowledgegate.in/gate
Closure Properties of Regular Languages
• Regular languages are closed under following operations
• Kleen Closure
• Positive closure
• Complement
• Reverse Operator
• Prefix Operator
• Suffix operator
• Concatenation
• Union
• Intersection
• Set Difference operator
Symmetric Differe nc e
• h t tp://www.knowledgegate.in/gate
Kleene Closure set
RL Reverse
DCFL N CFL Y N
Union
NYN NNYY
Y
Positive Closure Y NNN YYY
Y Subset
Intersection Y N
Y Y
Concatenation N
Y
Complement
Y
In N
Y ters
Set Difference ecti
on
wit
h
reg
Y ular
CSL Y Y Y RS Y Y
YYYY
RES N Y
YY
Y Y Y
N
Y Y Y
Y Y N
Y Y N
Y Y
N Y
RL CFL
∈ Free DCFL
Y
Substitution
Homomorphis
YYYY
m
Quotient with
Y N Y
∈ Free regular set
now led Y
Homomorphis Y N
m
Y
Y Y
Inverse
Y N
Homomorphis
m Substitution
Y N
CSL RS RES
NYYN N Y
Y Y Y
N Y Y
N Y
Y Y
Y Y
Pigeonhole Principle
• The Pigeonhole Principle is a fundamental principle of
combinatorial mathematics that states:
• If n items are put into m containers, with n>m, then at least one container must
• This principle seems intuitive, but it has powerful implications and can be used
to prove a variety of seemingly unrelated results across mathematics and
computer science.
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
Pumping Lemma For Regular Languages
● Pumping Lemma is used as a proof for irregularity of a language. Thus, if a language is
regular, it always satisfies pumping lemma. If there exists at least one string made from
pumping which is not in L, then L is surely not regular.
● The opposite of this may not always be true. That is, if Pumping Lemma holds, it does not
o |v| ≥ 1
o for all i ≥ 0: uviw ∈ L
● In simple terms, this means that if a string v is ‘pumped’, i.e., if v is inserted any number
of times, the resultant string still remains in L.
http://www.knowledgegate.in/gate
Process of pumping Lemma
● Suppose that we need to prove that language L is a non-regular.
● Assume that L is a regular language, then L must satisfy pumping lemma property.
● Choose z ∈ L such that |z| <= n, split z into 3 parts.
o |uv| ≤ n
o |v| ≥ 1
o If there exist at least one variable for i such that uviw L, then L does not satisfy
pumping lemma property so it is a contradiction, therefore language L is non-regular.
http://www.knowledgegate.in/gate
Q Proof that language L = {ambn | m=n} is non-regular?
http://www.knowledgegate.in/gate
Q Proof that language L = {anbn | n is a prime number} is non-regular?
http://www.knowledgegate.in/gate
Q Proof that language L = {an^2 | n>= 0} is non-regular?
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
PROBLEM
SOLVABLE UNSOLVABLE
DECIDABLE UNDECIDABLE
P TYPE NP TYPE
http://www.knowledgegate.in/gate
• SOLVABLE - A problem is said to be solvable if either we can solve it or
if we can prove that the problem cannot be solved
http://www.knowledgegate.in/gate
• P- if there exist a polynomial time algorithm to solve a problem then
problem is said to be decidable.
http://www.knowledgegate.in/gate
Decision properties
ii) Non-emptiness
iii) Finiteness
iv) Infiniteness
v) Membership
vi) Equality
http://www.knowledgegate.in/gate
Emptiness & Non-emptiness
• Step 1: - select the state that cannot be reached from the initial states & delete them
(remove unreachable states)
• Step 2: - if the resulting machine contains at least one final states, so then the finite
automata accepts the non-empty language.
• Step 3: - if the resulting machine is free from final state, then finite automata accepts
empty language.
http://www.knowledgegate.in/gate
Finiteness & Infiniteness
• Step 1: - Select the state that cannot be reached from the initial state & delete them
(remove unreachable states)
• Step 2: - Select the state from which we cannot reach the final state & delete them
(remove dead states)
• Step 3: - If the resulting machine contains loops or cycles then the finite automata
accepts infinite language
• Step 4: - If the resulting machine do not contain loops or cycles then the finite
automata accepts finite language.
http://www.knowledgegate.in/gate
Membership
• Membership is a property to verify an arbitrary string is accepted by a finite automaton or not
• Let M is a finite automata that accepts some strings over an alphabet, and let ‘w’ be any
string defined over the alphabet, if there exist a transition path in M, which starts at initial
state & ends in anyone of the final state, then string ‘w’ is a member of M, otherwise ‘w’ is
not a member of M.
http://www.knowledgegate.in/gate
Equality
• Two finite state automata M1 & M2 is said to be equal if and only if, they
accept the same language.
• Minimise the finite state automata and and the minimal DFA will be unique.
http://www.knowledgegate.in/gate
Infiniteness Equality
RL DCFL Y Y CFL Y Y Y
Emptiness
YYY YYNN
Y
Ambiguity N N
Y Y
Non-Emptiness
Y
∑*
NN
Y
Y Finiteness
Membership
Y
Y
CSL X X X RS N N
XXXX N
RES N
X
N Y N
N N
N N
N N
N N
N
Halting Y
http://wYww.knowYledgeg
atXe.in/gate Y
N
• Chapter-3 (Regular and Non-Regular Grammars):
Context Free Grammar(CFG)-Definition,
Derivations, Languages, Derivation Trees and
Ambiguity, Regular Grammars-Right Linear and Left
Linear grammars, Conversion of FA into CFG and
Regular grammar into FA, Simplification of CFG,
Normal Forms- Chomsky Normal Form(CNF),
Greibach Normal Form (GNF), Chomsky Hierarchy,
Programming problems based on the properties of
CFGs. http://www.knowledgegate.
in/gate
Introduction
• Language usually contains infinite number of strings.
• We cannot tabulate each and every string to represent the language,
therefore like automata, grammar is also a mathematical model of
representing a language, using which we can generate the entire language.
• Therefore, a grammar is usually thought of as a language generator.
http://www.knowledgegate.in/gate
Formal Grammar
A phrase-structure grammar (or simply a grammar) is a 4-tuple (VN, ∑, P, S), where
• S is a special variable (i.e., an element of VN (S ∈ Vn)) called the start symbol. Like every
automaton has exactly one initial state, similarly every grammar has exactly one start
symbol.
• P is a finite set whose elements are α → β. where α and β are strings on VN ⋃ ∑. α has at
least one symbol from VN, the element of P are called productions or production rules or
rewriting rules. {Σ U Vn}* some writer refers it as total alphabet
http://www.knowledgegate.in/gate
For a formal valid production
α🡪β
α ∈ {Σ U Vn}* Vn {Σ U
Vn}* β ∈ {Σ U Vn}*
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
Some points to note about productions
• Reverse substitution is not permitted. For example, if S → AB is a
production, then we can replace S by AB but we cannot replace AB by S.
• No inversion operation is permitted. For example, if S → AB is a production, it
is not necessary that AB →S is a production.
http://www.knowledgegate.in/gate
Defining a language by grammar
• The concept of defining a language using grammar is, starting from a start symbol using the
production rules of the grammar any time, deriving the string. Here every time during
derivation a production is used as its LHS is replaced by its RHS, all the intermediate
stages(strings) are called sentential forms. The language formed by the grammar consists of
all distinct strings that can be generated in this manner.
L (G) = {w | w ∈ ∑* , S 🡪* W}
• 🡪*(reflexive, transitive closure) means from s we can derive w in zero or more steps
http://www.knowledgegate.in/gate
• Using same idea, we do processing of natural languages in computers,
Actively used in compliers
• L (G) is the set of all terminal strings derived from the start symbol S.
• G1 and G2 are equivalent if L (G1) = L (G2).
http://www.knowledgegate.in/gate
Chomsky Classification of Languages
• Chomsky classified the grammars into four types in terms of productions (types 0-3).
• This hierarchy of grammars was described by Noam Chomsky in 1956. From type 0 to type
3, we will be putting more and more restrictions.
• We will see that more restrictive is grammar easy will be the language and more liberal is the
grammar difficult will be the language. Based on the production rules of the grammar, we
can classify the formal grammar into four types, based on which we generate different
languages.
http://www.knowledgegate.in/gate
• Avram Noam Chomsky (born December 7, 1928) is an American linguist, philosopher, cognitive
scientist, historian, social critic, and political activist. Sometimes called "the father of modern linguistics",
• Chomsky is also a major figure in analytic philosophy and one of the founders of the field of cognitive science. He
is Laureate Professor of Linguistics at the University of Arizona and Institute Professor Emeritus at
the Massachusetts Institute of Technology (MIT), and is the author of more than 150 books on topics such as
linguistics, war, politics, and mass media. Ideologically, he aligns with anarcho-syndicalism and libertarian
socialism.
• Born to Jewish immigrants in Philadelphia, Chomsky developed an early interest in anarchism from alternative
bookstores in New York City. He studied at the University of Pennsylvania. During his postgraduate work in
the Harvard Society of Fellows, Chomsky developed the theory of transformational grammar for which he earned
his doctorate in 1955. That year he began teaching at MIT, and in 1957 emerged as a significant figure in
linguistics with his landmark work Syntactic Structures, which played a major role in remodeling the study of
language.
• From 1958 to 1959 Chomsky was a National Science Foundation fellow at the Institute for Advanced Study. He
created or co-created the universal grammar theory, the generative grammar theory, the Chomsky hierarchy, and
the minimalist program. Chomsky also played a pivotal role in the decline of linguistic behaviorism, and was
particularly critical of the work of B. F. Skinner.
http://www.knowledgegate.in/gate
• An outspoken opponent of U.S. involvement in the Vietnam War, which he saw as an act of
American imperialism, in 1967 Chomsky rose to national attention for his anti-war essay "The
Responsibility of Intellectuals".
• Associated with the New Left, he was arrested multiple times for his activism and placed on
President Richard Nixon's Enemies List. While expanding his work in linguistics over subsequent
decades, he also became involved in the linguistics wars. In collaboration with Edward S.
Herman, Chomsky later articulated the propaganda model of media criticism in Manufacturing
Consent and worked to expose the Indonesian occupation of East Timor.
• His defense of freedom of speech, including Holocaust denial, generated significant controversy in
the Faurisson affair of the 1980s. Since retiring from MIT, he has continued his vocal political
activism, including opposing the 2003 invasion of Iraq and supporting the Occupy movement.
Chomsky began teaching at the University of Arizona in 2017.
• One of the most cited scholars alive, Chomsky has influenced a broad array of academic fields. He is
widely recognized as having helped to spark the cognitive revolution in the human sciences,
contributing to the development of a new cognitivistic framework for the study of language and the mind.
te
LANGUAGES AND AUTOMATA
http://www.knowledgegate.in/gate
Type 0 Grammar
• Also known as Unrestricted Grammar, phase structured grammar, recursively
enumerable grammar used to generate recursive enumerable language which is
accepted by a Turing machine.
α🡪β
α ∈ {Σ U Vn}* Vn {Σ U
Vn}* β ∈ {Σ U Vn}*
http://www.knowledgegate.in/gate
Type 1 Grammar
αAβ🡪αδβ
α , β ∈ {Σ U Vn}* A ∈ Vn δ ∈ {Σ U Vn}+
or
α🡪β
α ∈ {Σ U Vn}* Vn {Σ U
Vn}* β ∈ {Σ U Vn}+
|α| <= |β|
http://www.knowledgegate.in/gate
• As from the rule we can understand that we cannot have null production, in order to solve
that problem, Production S🡪∈, is allowed if S do not appear on the right-hand side of the
production.
• Also known as Context Free Grammar, which will generate context free language that will
be accepted by push down automata. (NPDA default case)
α🡪β
α ∈ Vn |α| =
1 β ∈ {Σ U Vn} *
http://www.knowledgegate.in/gate
Type 3 Grammar
• Used to generate Regular Grammar which will generate regular language which will
be accepted by finite machine.
• Regular grammar can be of two types either left linear or right linear.
A 🡪 a / Ba
A, B ∈ Vn |A| = |B| = 1
a ∈ ∑*
• Right regular grammar
A 🡪 a / aB
|A| =
|B| =
1a∈
A, B
∑*
∈ Vn
• however, if left-linear rules and right-linear rules are combined, the language need no longer
be regular.
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 aAb
A 🡪 aB / b
B🡪c
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 AB / Bb
A🡪b/c
B🡪d
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 aSb / ∈
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 aA / abS
A 🡪 bS / b
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 aAB
A 🡪 aA / ∈
B🡪b
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 AB
A 🡪 aA / ∈
B 🡪 bB / b
http://www.knowledgegate.in/gate
Q Consider the following grammar and identify it’s language?
S 🡪 aSa / bSb / ∈
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑ =
{a, b}, where every accepted string ‘w’ starts with substring s = abb
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}.
where every accepted string ‘w’ ends with substring s = bab
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑ =
{a, b}. where every accepted string ‘w’ contains sub string s = aba
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑ =
{a, b} such that every accepted string start and end with a.
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑ = {a, b}, such
that every string ‘w’ accepted must be like
i) |w| = 3 ii) |w|<=3 iii) |w|>=3
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 0(mod 3)?
http://www.knowledgegate.in/gate
Q Design a grammar that generates all strings over the alphabet ∑= {a,
b}, such that every string ‘w’ where |W| = 3(mod 4)?
http://www.knowledgegate.in/gate
Regular Grammar
to
Regular Expression
http://www.knowledgegate.in/gate
S 🡪 01S / 01
http://www.knowledgegate.in/gate
S 🡪 0011S / 01 / 10
http://www.knowledgegate.in/gate
S 🡪 01A / B11
A 🡪011A / 01
B 🡪 101B / 11
http://www.knowledgegate.in/gate
S 🡪 011A / 101B
A 🡪110A / 00
B 🡪 11B / S
http://www.knowledgegate.in/gate
Regular Grammar
to
(Finite Automata)
http://www.knowledgegate.in/gate
S 🡪 01S / 1
http://www.knowledgegate.in/gate
S 🡪 011S / 01
http://www.knowledgegate.in/gate
S 🡪 001S / 10A A
🡪 101A / 0 / 1
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
• Derivation: - The process of deriving a string is known as derivation.
E 🡪 E + E / E * E / E = E / id
http://www.knowledgegate.in/gate
• Sentential form: - Intermediate step involve in the derivation is known
as sentential form.
E 🡪 E + E / E * E / E = E / id
http://www.knowledgegate.in/gate
• Left most derivation: - the process of construction of parse tree by expanding
the left most non terminal is known as LMD and the graphical representation of
LMD is known as LMDT (left most derivation tree)
LMD
E
E🡪E+E
E*E
E🡪 E * E
E+E*E
E🡪 E = E
ID+E*E
E🡪 id
ID+ID*E
E🡪 id
E🡪 id
ID+ID*ID
http://www.knowledgegate.in/gate
• Right most derivation: - the process of construction of parse tree by expanding
the right most non terminal is known as RMD and the graphical representation
of RMD is known as RMDT (right most derivation tree)
RMD
E
E🡪E+E
E+E
E🡪 E * E
E+E*E
E🡪 E = E
E+E*ID
E🡪 id
E+ID*ID
E🡪 id
E🡪 id
ID+ID*ID
http://www.knowledgegate.in/gate
Sentential Form
E
E*E
E+E*E
ID+E*E
ID+ID*E
ID+ID*ID
S 🡪 aS/Sa/a
http://www.knowledgegate.in/gate
http://www.knowledgegate.in/gate
Unambiguous grammar: - The CFG is said to be unambiguous if there
exist only one parse tree for every string i.e. if there exist only one LMDT
or RMDT, then the grammar is unambiguous e.g.
S 🡪 aSb/ab
http://www.knowledgegate.in/gate
• Some CFL are called inherently ambiguous means there exist no unambiguous
CFG to generate the corresponding CFL, proved by Rohit Parikh 1961,
• {an bm cm dn } U {an bn cm dm }
http://www.knowledgegate.in/gate
• Grammar which is both left and right recursive is always ambiguous,
but the ambiguous grammar need not be both left and right recursive.
http://www.knowledgegate.in/gate
Simplification or Minimization of CFG
• The reason we simplify CFG to make it more efficient and compiler friendly.
• The process of deleting and eliminating of useless symbols, unit production and
null production is known as simplification of CFG.
http://www.knowledgegate.in/gate
Removal of Null or Empty productions
S 🡪 AbB A
🡪a/∈B
🡪b/∈
http://www.knowledgegate.in/gate
S 🡪 AB
A🡪a/∈
B🡪b/∈
http://www.knowledgegate.in/gate
S 🡪 aSb / ∈
http://www.knowledgegate.in/gate
Removal of unit productions
S 🡪 Aa
A🡪a/B
B🡪d
http://www.knowledgegate.in/gate
S 🡪 aAb A
🡪B/aB
🡪C/bC
🡪D/cD
🡪d
http://www.knowledgegate.in/gate
S 🡪 aSb / ∈
http://www.knowledgegate.in/gate
Removal of useless symbols
• The variables which are not involved in the derivation of any string is known
as useless symbol.
• Select the Variable that cannot be reached
from the start symbol of the grammar and C🡪d
remove them along with their all
production.
S 🡪 aAB A 🡪 a
B🡪b
• Select with
variable their
that are producti
reachabl ons
e from
the start
symbol
S🡪
but aA
which
does not /
derive aB
any
terminal A
, remove
them 🡪
along
b
http://www.knowledgegate.in/gate
S 🡪 aAB / bA / aC
A 🡪 aB / b
B 🡪 aC / d
http://www.knowledgegate.in/gate
Chomsky Normal Form
• The Grammar G is said to be in Chomsky Normal Form, if every
production is in the form
A 🡪 BC / a
B, C ∈ Vn
a∈Σ
http://www.knowledgegate.in/gate
• Avram Noam Chomsky (born December 7, 1928) is an American linguist,
philosopher, cognitive scientist, historian, social critic, and political activist. Sometimes
called "the father of modern linguistics",
http://www.knowledgegate.in/gate
S 🡪 aSb / ab
http://www.knowledgegate.in/gate
S 🡪 aAb / bB A
🡪a/b
B🡪b
http://www.knowledgegate.in/gate
• if CFG is in CNF, then for a derivation of string w, with length we need
exactly 2n -1 production. |w| = n, number of sentential forms will be
2n -1
http://www.knowledgegate.in/gate
Greiback Normal Form
A 🡪 aα
A ∈ Vn
a∈Σα
∈ Vn*
http://www.knowledgegate.in/gate
• Sheila Adele Greibach (born 6 October
1939 in New York City) is a researcher in
formal languages in computing, automata,
compiler theory and computer science.
http://www.knowledgegate.in/gate
S 🡪 aSb / ab
http://www.knowledgegate.in/gate
S 🡪 aAb / bB A
🡪a/b
B🡪b
http://www.knowledgegate.in/gate
• if CFG is in GNF, then for a derivation of string w, with length we need
exactly n production. |w| = n, number of sentential forms will be n
http://www.knowledgegate.in/gate
• Chapter-4 (Push Down Automata and Properties of
Context Free Languages): Nondeterministic Pushdown
Automata (NPDA)- Definition, Moves, A Language
Accepted by NPDA, Deterministic Pushdown
Automata(DPDA) and Deterministic Context free
Languages(DCFL), Pushdown Automata for Context
Free Languages, Context Free grammars for Pushdown
Automata, Two stack Pushdown Automata, Pumping
Lemma for CFL, Closure properties of CFL, Decision
Problems of CFL, Programming problems based on the
ww.knowledgegate.in/gate
properties ohfttCpF:/L/sw.
CONTEXT-FREE LANGUAGES AND PUSH DOWN AUTOMATA
http://www.knowledgegate.in/gate
Push Down Automata
• We Already understand the limitation of finite automata, that it cannot do the infinite
comparison between the symbols.
• Let us consider L = {an bn | n >= 1}. This is not regular, as it has to remember the number of a's in a
string and so it will require an infinite number of states, which is logically not possible.
• This difficulty can be avoided by adding an auxiliary memory in the form of a 'stack'. The reason
we choose stack because it is the simplest memory possible.
• This type of arrangement where a finite automaton has a stack leads to the generation of a
pushdown automaton.
http://www.knowledgegate.in/gate
BLOCK DIAGRAM OF PDA
• Finite control unit is also called as memory unit it is static and limited. So to process the
i/p string if the static memory is not sufficient then we can use the stack.
• i/p tape is divided into cells where is cell is capable of holding one symbol at a time. At stack
of infinite size, which support three operations push, pop and skip.
• The accepting power of a pda is more than that of finite automata and less than that of
linear bounder automata
• The power of non-deterministic pda is more than the power of deterministic pda.
http://www.knowledgegate.in/gate
Formal Definition of DPDA
http://www.knowledgegate.in/gate
Representation of States
(1) PUSH – one symbol can be inserted into the stack at one
time. δ(qi, a, z0) = (qj, az0)
http://www.knowledgegate.in/gate
Representation of States
(2) POP – one symbol can be deleted from the stack at one
time. δ(qi, a, z0) = (qj, ε)
http://www.knowledgegate.in/gate
Representation of States
(3) SKIP – IT means no stack operation, status of the stack will remain same, before
a after the operation
δ(qi, a, z0) = (qj, z0)
note- if pda perform a push or a pop operation at least one’s during processing of
string than we say that pda is using the stack.
http://www.knowledgegate.in/gate
Instantaneous Description (ID)
• An initial ID is (q0, x, Z0), this means that initially the pda is in the initial state q0, the input
string to be processed is x and the PDS has only one symbol, namely Z0.
http://www.knowledgegate.in/gate
ACCEPTANCE BY PDA
• There is no change in the language acceptance capability of the pda either
we accept by final state of empty stack.
http://www.knowledgegate.in/gate
n n
Q Design a Deterministic Push Down Automata for {a b | n >= 1} ?
http://www.knowledgegate.in/gate
n 2n
Q Design a Deterministic Push Down Automata for {a b | n >= 1} ?
http://www.knowledgegate.in/gate
r
Q Design a PDA for {w c w | w ∈(a, b)*} ?
http://www.knowledgegate.in/gate
Q Construct PDA that accepts L = {|w|a = b | w € (a, b)*} ?
http://www.knowledgegate.in/gate
Non- Deterministic PDA
• Non- Deterministic PDA can also be defined using 7 tuples.
• δ: Q x {∑ U ∈} x Γ → 2(Q x Γ* )
• i.e. on a given input symbol and stack symbol a NPDA can move to more than one state.
• Rest all other tuples are same as DPDA.
http://www.knowledgegate.in/gate
r *
Q Construct pda that accepts a language L = {w w | w € (a, b) }?
http://www.knowledgegate.in/gate
Decision properties
Following properties are decidable in case a CFL. Here we will use Grammar model
to proof decision properties.
i) Emptiness
ii) Non-emptiness
iii) Finiteness
iv) Infiniteness
v) Membership
http://www.knowledgegate.in/gate
Q consider the following CFG and identify which of the following CFG generate Empty language?
S 🡪 aAB / Aa
A🡪a
S 🡪 aAB A
🡪a/b
S 🡪 aAB / aB A
🡪 aBb
B 🡪 aA
http://www.knowledgegate.in/gate
Q consider the following CFG and identify which of the following CFG generate Finite
language?
S 🡪 SS / AB
A 🡪 BC / a
B 🡪 CC / b
S 🡪 AB
A🡪B/a
S 🡪 AB
A 🡪 BC / a
B 🡪 CC / b
C 🡪 AB
http://www.knowledgegate.in/gate
Q consider the following CFG and check out the membership properties?
S 🡪 AB / BB
A 🡪 BA / AS / b
B 🡪 AA / SB / a
w1 = aba
w2 = abaab
w3 = abababba
http://www.knowledgegate.in/gate
CYK algorithm
• In computer science, the Cocke–Younger–Kasami algorithm (alternatively called CYK, or CKY) is
a parsing algorithm for context-free grammars, named after its inventors, John Cocke, Daniel Younger
and Tadao Kasami. It employs bottom-up parsing and dynamic programming.
• The standard version of CYK operates only on context-free grammars given in Chomsky normal
form (CNF). However any context-free grammar may be transformed to a CNF grammar expressing the
same language (Sipser 1997).
• The importance of the CYK algorithm stems from its high efficiency in certain situations. Using Big O
notation, the worst case running time of CYK is O (n3 .|G|), Where n is the length of the parsed string
and |G| is the size of the CNF grammar G.
i) Equality
ii) Ambiguity
http://www.knowledgegate.in/gate
Infiniteness Equality
RL DCFL Y Y CFL Y Y Y
Emptiness
YYY YYNN
Y
Ambiguity N N
Y Y
Y Y
Non-Emptiness
∑*
NNY
Y
Y Finiteness
Halting
Membership
Y Y
Y
CSL X X X RS N N
XXXX N
RES N
X
N Y N
X
Y
N N
N N N
N N
N N
N
Closure Properties of Deterministic Context Free Languages
• Complement
• Inverse Homeomorphism
• Deterministic Context Free Languages are not closed under following operations
• Union
• Concatenation
• Kleen closure
• homomorphism
• Substitution
• Reverse operator
• Intersection
http://www.knowledgegate.in/gate
Closure Properties of Context Free Languages
• Context Free Languages are closed under following operations
• Union
• Concatenation
• Kleen Closure
• Substitution
• Homomorphism
• Inverse Homomorphism
• Reverse Operator
• Complement
• Symmetric Difference
http://www.knowledgegate.in/gate
h
RL r DCFL N N CFL Y N
Union Y e
Positive Closure
g
u Y N
l
a
Y r
Intersection Y s
Concatenation
e
t
N N N N Y Y Y
Reverse NYY YY
Y
Complement Y N N
I Y
n
t Subset
Y e
r
Set Difference s
e N
c
t
Y i
o
Kleene Closure n
w
i
t
CSL Y Y RS N
Y Y Y
RES
N
Y Y
Y Y Y Y Y N
Y
YY
Y Y
N
Y Y
Y Y
N Y
Y Y
Y
http://www.knowledgegate.in/gate
RL CFL
∈ Free DCFL N
Substitution
Homomorphi Y Y Y
sm Y Y
Quotient with
∈ Free regular set
N N YYY
Homomorphi
sm
Y Y
Inverse N Y
Homomorphi Y
sm Y
Substitution
Y
CSL RS
RES
N Y Y
N Y
NYN
Y Y
Y Y
N Y
Y Y
Y Y
http://www.knowledgegate.in/gate
• Chapter-5 (Turing Machines and Recursive Function
Theory): Basic Turing Machine Model, Representation
of Turing Machines, Language Acceptability of Turing
Machines, Techniques for Turing Machine Construction,
Modifications of Turing Machine, Turing Machine as
Computer of Integer Functions, Universal Turing
machine, Linear Bounded Automata, Church’s Thesis,
Recursive and Recursively Enumerable language, Halting
Problem, Post’s Correspondance Problem, Introduction
to Recursive Function Theory.
http://www.knowledgegate.in/gate
Turing Machine
• The Church-Turing thesis states that any algorithmic procedure that can be carried out by human
beings/computer can be carried out by a Turing machine.
• It has been universally accepted by computer scientists that the Turing machine provides an ideal theoretical
model of a computer.
http://www.knowledgegate.in/gate
• Turing machines are useful in several ways:
• As an automaton, the Turing machine is the most general model.
• It accepts type-0 languages.
• It can also be used for computing functions.
• Turing machines are also used for determining the undecidability of certain
languages and measuring the space and time complexity of problems.
http://www.knowledgegate.in/gate
Components of Turing Machine
Infinite Tape
• An input infinite tape can be, used as an input buffer and also as a member element.
• It is random accessible. It is of infinite length divided into cells and each cell is capable
of holding only one tape symbol.
• It is also called 2-way infinite tape.
http://www.knowledgegate.in/gate
Components of Turing Machine
Read-Write Buffer
• Read the data from the tape and can also write the data over the tape. After reading
the symbol from the tape, the read/write header moves to exactly one cell either in left
or right direction.
http://www.knowledgegate.in/gate
Components of Turing Machine
• As per the control unit, the transitions will take place, and will finally lead to some output.
http://www.knowledgegate.in/gate
FORMAL DEFINITION
A Turing machine M is a 7-tuple, namely (Q, ∑, Γ, δ, q0, b, F), where
• b ∈ Γ is the blank.
• δ is the transition function mapping δ: Q ×ℾ -> Q× ℾ × (L/R). It says that, on providing a tape symbol, from a
particular state there will be a transition to another state, with a different or same tape symbol with defining
whether next the machine needs to move in left/ right.
Three representations:
• Instantaneous descriptions using move-relations.
• Transition table, and
• Transition diagram (transition graph).
http://www.knowledgegate.in/gate
LANGUAGE ACCEPTABILITY BY TURING MACHINES
• M does not accept w if the machine M either halts in a non-accepting state or does not
halt and goes into a loop.
http://www.knowledgegate.in/gate
n n n
Q Design a Turing machine for L = {a b c | n >= 0}?
http://www.knowledgegate.in/gate
Q Design a Turing machine for L = {w c w | w ∊ {0, 1}* }?
http://www.knowledgegate.in/gate
Q Design a Turing machine for addition of two number in unary?
http://www.knowledgegate.in/gate
Q Design a Turing machine for converting unary number into binary
number?
http://www.knowledgegate.in/gate
Versions of Turing Machine
http://www.knowledgegate.in/gate
• On the basis of determinism of the next transition to a state on a particular
input, Turing Machine are divided in two types-
• Determinism Turing Machine.
• In multi-tape Turing machine, there can be more than one tape and corresponding
head pointers, but it does not add any power to Turing machine.
• Every multi-tape TM can be converted into single tape TM.
• Jumping TM, where it is allowed to take more that one moves in one transaction δ: Q ×ℾ -> Q×
ℾ × (L/R) ×{n}.
• Multi-head TM
• FA with a Queue
• TM with only 3 states
• Multi-tape Turing Machine with stay option and at most 2 states.
http://www.knowledgegate.in/gate
0 1 B
• The state of Turing machine, where no transition is defined or required is known as Halt.
There are two types of Halt-
• Final Halt- Machine has been halted on final state, then it is known as Final halt and
hence it depicts that machine is accepted.
• Non-Final Halt-Machine has been halted on non- final state, then it is known as non-
final halt and hence the string is rejected.
• After taking an input string, there are three possibilities for Turing Machine
• It may go to Final halt.
• Final Halt and Non- Final Halt have been described above. After taking an input string, if
the machine goes to infinite loop, then we can’t say whether the string is
Accepted/Rejected.
http://www.knowledgegate.in/gate
• So, broadly Recursively Enumerable Languages are categorized as-
to be REL, where for all, ‘w’ that belongs to L, machine will go to final halt, and for all ‘w’
that does not belongs to L, machine will either go to non-final halt or infinite loop. Hence,
membership property is not defined here.
• If a set and its complement both are recognizable, then the set is decidable.
• There are some sets which are not recognizable (even members can’t be identified)
because there are more languages than programs.
http://www.knowledgegate.in/gate
Universal Turing Machine
http://www.knowledgegate.in/gate
Universal Turing Machine
• The universal machine essentially achieves this by reading both the description
of the machine to be simulated as well as the input to that machine from its own
tape.
http://www.knowledgegate.in/gate
• Every Turing machine computes a certain fixed partial computable function from the
input strings over its alphabet. In that sense it behaves like a computer with a fixed
program.
• However, we can encode the action table of any Turing machine in a string. Thus we can
construct a Turing machine that expects on its tape a string describing an action table
followed by a string describing the input tape, and computes the tape that the encoded Turing
machine would have computed. Turing described such a construction in complete detail in his
1936 paper:
• "It is possible to invent a single machine which can be used to compute any computable
sequence. If this machine U is supplied with a tape on the beginning of which is written the
S.D ["standard description" of an action table] of some computing machine M, then U will
compute the same sequence as M.
http://www.knowledgegate.in/gate
Linear Bounded Automata
http://www.knowledgegate.in/gate
A Linear Bounded Automaton (LBA) is similar to Turing Machine with
property stated below:
•Turing Machine with a bounded finite length of the tape.
http://www.knowledgegate.in/gate
Turing-Church Thesis
• Concept Origin: Independently developed by Alan Turing and Alonzo Church in
the 1930s, establishing a fundamental principle in computer science about
computable functions.
http://www.knowledgegate.in/gate
1. Turing Machines: Turing proposed the concept of a 'Turing machine',
a theoretical computing machine that can simulate any algorithm's
logic.
http://www.knowledgegate.in/gate
Decision properties
• Following properties are decidable in case a RS.
• Membership
Non-
Y Y Y X N N
Emptiness
Finiteness Y Y Y X N N
Infiniteness Y Y Y X N N
Membershi
Y Y Y X Y N
p
Equality Y N N X N N
Ambiguity Y N N X N N
∑* Y N N X N N
Halting Y Y Y X Y N
http://www.knowledgegate.in/gate
Closure Properties of Recursive Set
• Recursive languages are closed under following operations
• Union
• Concatenation
• Intersection
• Reverse
• Complement
• Inverse homomorphism
• Set Difference
• Homomorphism
• Substitution
http://www.knowledgegate.in/gate
Closure Properties of Recursive Enumerable Set
• Union
• Concatenation
• Kleen Closure
• Intersection
• Substitution
• Homomorphism
• Inverse Homomorphism
• Compliment
• Set Difference
http://www.knowledgegate.in/gate
RL DCFL CFL CSL RS RES
Union Y N Y Y Y Y
Intersection Y N N Y Y Y
Complement Y Y N Y Y N
Set Difference Y N N Y Y N
Kleene Closure Y N Y Y Y Y
Positive Closure Y N Y Y Y Y
Concatenation Y N Y Y Y Y
Intersection with
Y Y Y Y Y Y
regular set
Reverse Y Y Y Y Y Y
Subset N N N N N N
RL DCFL CFL CSL RS RES
Y N N N Y
Homomorphism Y
N Y Y Y
∈ Free Homomorphism Y Y
Y Y Y Y
Inverse Homomorphism Y Y
Substitution Y N Y N N
Y
Y N Y Y Y Y
∈ Free Substitution
N Y Y
Quotient with regular set Y
now led
Y Y