Geeksforgeeks Theory of Computation and Automata Lecture Notes
Geeksforgeeks Theory of Computation and Automata Lecture Notes
Now, let’s understand the basic terminologies, which are important and
frequently used in Theory of Computation.
Alphabets (Σ): Alphabets are set of symbols, which are always finite.
String: String is a finite sequence of symbols from some alphabet.
String is generally denoted as w and length of a string is denoted as
|w|.
Conclusion:
For alphabet {a, b} with length n, number of
strings can be generated = 2n.
Powers of ‘ Σ ‘ :
Say Σ = {a,b} then
Σ0 = Set of all strings over Σ of length 0. {ε}
Σ1 = Set of all strings over Σ of length 1. {a, b}
Σ2 = Set of all strings over Σ of length 2. {aa, ab, ba, bb}
i.e. |Σ2|= 4 and Similarly, |Σ3| = 8
Σ* is a Universal Set.
Σ* = Σ0 U Σ1 U Σ2 ..........
= {ε} U {a, b} U {aa, ab, ba, bb}
= ............. //infinite language.
References –
cs.stanford.edu
Wikipedia
abhishek1
WorKing to be bEst veRsion of MySelf
If you like GeeksforGeeks and would like to contribute, you can also
write an article using contribute.geeksforgeeks.org or mail your article
to [email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any
issue with the above content.
Chomsky Hierarchy
According to chomsky hierarchy, grammars are divided of 4 types:
In Type 0
Type-0 grammars include all formal grammars. Type 0 grammar
language are recognized by turing machine. These languages are also
known as the recursively enumerable languages.
is ( V + T)* V ( V + T)*
V : Variables
T : Terminals.
is ( V + T )*.
In type 0 there must be at least one variable on Left side of production.
For example,
Sab –> ba
A –> S.
| | <= | |
| | = 1.
Their is no restriction on .
For example,
S –> AB
A –> a
B –> b
for example :
S –> ab.
REFERENCES
https://en.wikipedia.org/wiki/Chomsky_hierarchy
In a DFA, for a particular input character, machine goes to one state only.
A transition function is defined on every state for every input symbol. Also
in DFA null (or ε) move is not allowe, i.e., DFA can not change state
without any input character.
For example, below DFA with ∑ = {0, 1} accepts all strings ending with 0.
One important thing to note is, there can be many possible DFAs for a
pattern. A DFA with minimum number of states is generally preferred.
δ: Transition Function
δ: Q X (∑ U ϵ ) --> 2 ^ Q.
As you can see in transition function for any input including null (or
&epsilon), NFA can go to any state number of states.
For example, below is a NFA for above problem
One important thing to note is, in NFA, if any path for an input string
leads to a final state, then the input string accepted. For example, in
above NFA, there are multiple paths for input string “00”. Since, one of
the paths leads to a final state, “00” is accepted by above NFA.
Regular Expressions
Regular Expressions are used to denote regular languages. An
expression is regular if:
Regular
Regular Languages
Expression
Solution : Option A says that it must have substring 00. But 10101 is
also a part of language but it does not contain 00 as substring. So it is
not correct option.
Option B says that it can have maximum two 0’s but 00000 is also a
part of language. So it is not correct option.
Option C says that it must contain atleast two 0. In regular expression,
two 0 are present. So this is correct option.
Option D says that it contains all strings that begin and end with either
0 or 1. But it can generate strings which start with 0 and end with 1 or
vice versa as well. So it is not correct.
Even number of a’s : The regular expression for even number of a’s
is (b|ab*ab*)*. We can construct a finite automata as shown in Figure
1.
The above automata will accept all strings which have even number
of a’s. For zero a’s, it will be in q0 which is final state. For one ‘a’, it
will go from q0 to q1 and the string will not be accepted. For two a’s at
any positions, it will go from q0 to q1 for 1st ‘a’ and q1 to q0 for
second ‘a’. So, it will accept all strings with even number of a’s.
The above automata will accept all binary numbers divisible by 3. For
1001, the automata will go from q0 to q1, then q1 to q2, then q2 to q1
and finally q2 to q0, hence accepted. For 0111, the automata will go
from q0 to q0, then q0 to q1, then q1 to q0 and finally q0 to q1, hence
rejected.
The language “aba” over the set of alphabets {a, b} can be generated
using regular expressions,
But we consider the least star height. Therefore the star height of the
regular language “aba” is one.
h(a*(b a*)*) = 2
h((a b*) + (a* a b*)*b)*) = 3
h(a) = 0
For example – consider the set of alphabets {x, y}. The star height of the
regular expression for the regular language “all strings beginning and
ending with x”, i.e
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Step 1 –
If the start state is an accepting state or has transitions in, add a new
non-accepting start state and add an €-transition between the new
start state and the former start state.
Step 2 –
If there is more than one accepting state or if the single accepting
state has transitions out, add a new accepting state, make all other
states non-accepting, and add an €-transition from each former
accepting state to the new accepting state.
Step 3 –
For each non-start non-accepting state in turn, eliminate the state and
update transitions accordingly.
Example :-
Solution :-
Step 1
Step 2
Step 3
2. Arden’s Theorem – Let P and Q be 2 regular expressions. If P does
not contain null string, then following equation in R, viz R = Q + RP, Has
a unique solution by R = QP*
Assumptions –
1. For getting the regular expression for the automata we first create
equations of the given form for all the states
q1 = q1w11 +q2w21 +…+qnwn1 +€ (q1 is the initial state)
q2 = q1w12 +q2w22 +…+qnwn2
.
.
.
qn = q1w1n +q2w2n +…+qnwnn
Note – For parallel edges there will be that many expressions for that
state in the expression.
Example :-
Solution :-
Here the initial state is q2 and the final state is q1.
The equations for the three states q1, q2, and q3 are as follows ?
q1 = q1a + q3a + € ( € move is because q1 is the initial state)
q2 = q1b + q2b + q3b
q3 = q2a
Now, we will solve these three equations ?
q2 = q1b + q2b + q3b
= q1b + q2b + (q2a)b (Substituting value of q3)
= q1b + q2(b + ab)
= q1b (b + ab)* (Applying Arden’s Theorem)
q1 = q1a + q3a + €
= q1a + q2aa + € (Substituting value of q3)
= q1a + q1b(b + ab*)aa + € (Substituting value of q2)
= q1(a + b(b + ab)*aa) + €
= € (a+ b(b + ab)*aa)*
= (a + b(b + ab)*aa)*
Hence, the regular expression is (a + b(b + ab)*aa)*.
Practicing the following questions will help you test your knowledge. All
questions have been asked in GATE in previous years or in GATE Mock
Tests. It is highly recommended that you practice them.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
DFA for Strings not ending with “THE”
Problem – Accept Strings that not ending with substring “THE”. Check if
a given string is ending with “the” or not. The different forms of “the”
which are avoided in the end of the string are:
All those strings that are ending with any of the above mentioned forms
of “the” are not accepted.
Input : XYzabCthe
Output : NOT ACCEPTED
Input : Themaliktth
Output : ACCEPTED
else if (dfa == 1)
state1(str[i]);
else if (dfa == 2)
state2(str[i]);
else
state3(str[i]);
}
// driver code
int main()
{
char str[] = "forTHEgeeks";
if (isAccepted(str) == true)
printf("\nACCEPTED\n");
else
printf("NOT ACCEPTED\n");
return 0;
}
Output:
ACCEPTED
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Pattern Searching
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
DFA of a string with at least two 0’s and
at least two 1’s
Problem – Draw detereministic finite automata (DFA) of a string with at
least two 0’s and at least two 1’s.
The first thing that come to mind after reading this question us that we
count the number of 1’s and 0’s. Thereafter if they both are at least 2 the
string is accepted else not accepted. But we do not have any concept of
memory in a DFA so we cannot do it by this method.
Input : 1 0 1 1 0 0
Output : Accepted
Input : 1 1 1 0 1
Output : Not accepted
Approach Used –
The first thing we observe is that both 0’s and 1’s should be at least 2. If
any of these is less than 2, then string will not be accepted. In this string
will be accepted in only last case where both 0’s and 1’s will be at least 2.
Q0 0 0
Q1 0 1
Q2 0 >=2
Q3 1 0
Q4 1 1
Q5 1 >=2
Q6 >=2 0
Q7 >=2 1
Q8 ACCEPTED >=2 >=2
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
DFA in LEX code which accepts even
number of zeros and even number of
ones
Lex is a computer program that generates lexical analyzers, which is
commonly used with the YACC parser generator. Lex, originally written
by Mike Lesk and Eric Schmidt and described in 1975,is the standard
lexical analyzer generator on many Unix systems, and an equivalent tool
is specified as part of the POSIX standard. Lex reads an input stream
specifying the lexical analyzer and outputs source code implementing the
lexer in the C programming language.
Approach –
LEX provides us with an INITIAL state by default. So in order to make a
DFA, use this initial state as the initial state of the DFA. Define two more
states A and B where B is the dead state that would be use if encounter
a wrong or invalid input. When user get input which is an invalid input,
move to state B and print message “INVALID” and if user reaches
INITIAL state from state A with a “\n” then display a message “Not
Accepted”. But if user get a \n on the initial state, user display a message
“Accepted”.
Examples –
Input : 1001
Output : Accepted
Input : hjabdba
Output : INVALID
To implement the above DFA, user needs to write the below code in a lex
file with a .l extention.
NOTE :
To compile a lex program, user need a UNIX system and flex which
can be installed using sudo apt-get install flex
With all the above specification open unix terminal and do the
following:
1. Use the lex program to change the specification file into a C
language program. The resulting program is in the lex.yy.c file.
2. Use the cc command with the -ll flag to compile and link the
program with a library of lex subroutines. The resulting executable
program is in the a.out file.
lex lextest
cc lex.yy.c -lfl
Code –
%{
%}
%s A B
%%
<INITIAL>1 BEGIN INITIAL;
<INITIAL>0 BEGIN A;
<INITIAL>[^0|\n] BEGIN B;
<INITIAL>\n BEGIN INITIAL; printf("Accepted\n");
<A>1 BEGIN A;
<A>0 BEGIN INITIAL;
<A>[^0|\n] BEGIN B;
<A>\n BEGIN INITIAL; printf("Not Accepted\n");
<B>0 BEGIN B;
<B>1 BEGIN B;
<B>[^0|\n] BEGIN B;
<B>\n {BEGIN INITIAL; printf("INVALID\n");}
%%
void main()
{
yylex();
}
Output –
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Misc
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Conversion from NFA to DFA
An NFA can have zero, one or more than one move from a given state on
a given input symbol. An NFA can also have NULL moves (moves
without input symbol). On the other hand, DFA has one and only one
move from a given state on a given input symbol.
Example
Consider the following NFA shown in Figure 1.
Step 1: Q’ = ɸ
Step 2: Q’ = {q0}
Step 3: For each state in Q’, find the states for each input symbol.
Currently, state in Q’ is q0, find moves from q0 on input symbol a and b
using transition function of NFA and update the transition table of DFA.
Now, moves from state {q0, q2} on different input symbols are not
present in transition table of DFA, we will calculate it like:
δ’ ( { q0, q2 }, a ) = δ ( q0, a ) ∪ δ ( q2, a ) = { q0, q1 }
δ’ ( { q0, q2 }, b ) = δ ( q0, b ) ∪ δ ( q2, b ) = { q0 }
Now we will update the transition table of DFA.
NFA with (null) or ∈ move : If any finite automata contains ε (null) move
or transaction, then that finite automata is called NFA with ∈ moves
Example :
Consider the following figure of NFA with ∈ move :
A B, C A B
B – B C
C C C –
∈ closure(A) : {A, B, C}
∈ closure(B) : {B, C}
∈ closure(C) : {C}
Step 3 : If any new state is found take it as current state and repeat
step 2.
Step 4 : Do repeat Step 2 and Step 3 until no new state present in
DFA transition table.
Step 5 : Mark the states of DFA which contains final state of NFA as
final states of DFA.
STATES 0 1
A, B, C B, C A, B, C
B, C C B, C
C C C
Examples :
Input : 6
2
FC - BF
- C -
- - D
E A -
A - BF
- - -
Output :
STATES OF NFA : A, B, C, D, E, F,
STATES |0 |1 eps
--------+------------------------------------
A |FC |- |BF
B |- |C |-
C |- |- |D
D |E |A |-
E |A |- |BF
F |- |- |-
e-Closure (B) : B
e-Closure (C) : CD
e-Closure (D) : D
e-Closure (F) : F
********************************************************
STATES |0 |1
--------+-----------------------
ABF |CDF |CD
CDF |BEF |ABF
CD |BEF |ABF
BEF |ABF |CD
Input :
9
2
- - BH
- - CE
D - -
- - G
- F -
- - G
- - BH
I - -
- - -
Output :
STATES OF NFA : A, B, C, D, E, F, G, H, I,
e-Closure (C) : C
e-Closure (E) : E
e-Closure (H) : H
e-Closure (I) : I
********************************************************
STATES |0 |1
--------+-----------------------
ABCEH |BCDEGHI |BCEFGH
BCDEGHI |BCDEGHI |BCEFGH
BCEFGH |BCDEGHI |BCEFGH
Explanation :
First line of the input contains the number of states (N) of NFA. Second
line of the input says the number of input symbols (S). In example1
number of states of NFA is 6 i.e.( A, B, C, D, E, F) and 2 input symbols
i.e. ( 0, 1). Since we are working on NFA with ∈ move, ∈ will be added
as an extra input symbol. The next N lines contains the transition values
for every state of NFA. The value of ith row, jth column indicates
transition value for ith state on jth input symbol. Here in example1
transition(A, 0) : FC.
Output contains the NFA, ∈ closure for every states of the corresponding
NFA and DFA obtained by converting the input NFA. States and input
symbols of the DFA are also specified.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 100
char NFA_FILE[MAX_LEN];
char buffer[MAX_LEN];
int zz = 0;
int last_index = 0;
FILE *fp;
int symbols;
int i;
j = ((int)(S[i] - 65));
strcpy(temp, &NFT[j][M]);
if (strcmp(temp, "-") != 0) {
sz = strlen(temp);
g = 0;
// Driver Code
int main() {
int i, j, states;
char T_buf[MAX_LEN];
dfa_states[last_index - 1].count = 1;
bzero((void *)buffer, MAX_LEN);
strcpy(buffer, &closure_table[0]);
strcpy(&dfa_states[last_index++].states, buffer);
int Sm = 1, ind = 1;
int start_index = 1;
return 0;
}
Agnibha_Chandra
Btech(3rd year) in Information Technology from IIEST shibpur
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to
share more information about the topic discussed above.
Minimization of DFA
Suppose there is a DFA D < Q, ∑, q0, δ, F > which recognizes a
language L. Then the minimized DFA D < Q’, ∑, q0, δ’, F’ > can be
constructed for language L as:
Step 1: We will divide Q (set of states) into two sets. One set will contain
all final states and other set will contain non-final states. This partition is
called P0.
Step 2: Initialize k = 1
Step 3: Find Pk by partitioning the different sets of Pk-1. In each set of Pk-
1, we will take all possible pair of states. If two states of a set are
distinguishable, we will split the sets into different sets in Pk.
Step 4: Stop when Pk = Pk-1 (No change in partition)
Step 5: All states of one set are merged into one. No. of states in
minimized DFA will be equal to no. of sets in Pk.
For set { q5 }:
Since we have only one state in this set, it can’t be further partitioned. So,
P2 = { { q1, q2, q4 }, { q0, q3 }, { q5 } }
Since, P1=P2. So, this is the final partition. Partition P2 means that q1,
q2 and q4 states are merged into one. Similarly, q0 and q3 are merged
into one. Minimized DFA corresponding to DFA of Figure 1 is shown in
Figure 2 as:
A. 1 and 3 only
B. 2 and 4 only
C. 2 and 3 only
D. 3 and 4 only
Figure 1
In the moore machine shown in Figure 1, the output is represented with each input sta
of output for a moore machine is greater than input by 1.
Input: 11
Transition: δ (q0,11)=> δ(q2,1)=>q2
Output: 000 (0 for q0, 0 for q2 and again 0 for q2)
Mealy Machines: Mealy machines are also finite state machines with output value a
on
present state and current input symbol. It can be defined as (Q, q0, ∑, O, δ, λ’) where
In the mealy machine shown in Figure 1, the output is represented with each input sym
state separated
by /. The length of output for a mealy machine is equal to the length of input.
Input:11
Transition: δ (q0,11)=> δ(q2,1)=>q2
Output: 00 (q0 to q2 transition has Output 0 and q2 to q2 transition also has Outp
Input=0 Input=1
q0 q1 0 q2 0
q1 q1 0 q2 1
q2 q1 1 q2 0
Table 1
Step 1. First find out those states which have more than 1 outputs associated with the
which have both output 0 and 1 associated with them.
Step 2. Create two states for these states. For q1, two states will be q10 (state with o
output 1). Similarly for q2, two states will be q20 and q21.
Step 3. Create an empty moore machine with new generated state. For moore machi
each state irrespective of inputs.
Input=0 Input=1
Present State Next State Next State Output
q0
q10
q11
q20
q21
Table 2
Step 4. Fill the entries of next state using mealy machine transition table shown in Tab
state is q10 (q1 with output 0). Similarly, for q0 on input 1, next state is q20 (q2 with o
Input=0 Input=1
Present State Next State Next State Output
q0 q10 q20 0
Table 3
Let us take the moore machine of Figure 1 and its transition table is shown in Table 3.
Step 1. Construct an empty mealy machine using all states of moore machine as sho
Input=0 Input=1
Present State Next State Output Next State Output
q0
q10
q11
q20
q21
Table 4
Step 2: Next state for each state can also be directly found from moore machine trans
Input=0 Input=1
q0 q10 q20
Table 5
q0 q10 0 q20 0
q10 q10 0 q21 1
Table 6
Step 4: As we can see from table 6, q10 and q11 are similar to each other (same va
different Input). Similarly, q20 and q21 are also similar. So, q11 and q21 can be elimin
Input=0 Input=1
Table 7
This is the same mealy machine shown in Table 1. So we have converted mealy to m
back moore to mealy.
Example: The Finite state machine described by the following state diagram with A a
label is x / y and x stands for 1-bit input and y stands for 2- bit output?
Outputs the sum of the present and the previous bits of the input.
Solution: Let us take different inputs and its output and check which option works:
Input: 01
Output: 00 01 (For 0, Output is 00 and state is A. Then, for 1, Output is 01 and state
Input: 11
Output: 01 10 (For 1, Output is 01 and state is B. Then, for 1, Output is 10 and state
As we can see, it is giving the binary sum of present and previous bit. For first bit, pre
Note – NFA and DFA both have same power that means if NFA can
recognized an language L then DFA can also be defined to do so and if
DFA can recognized an language L then NFA can also be defined to do
so.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Context Free Grammar and Context Free
Languages
Relationship between grammar and
language
A grammar is a set of production rules which are used to generate strings
of a language. In this article, we have discussed how to find the language
generated by a grammar and vice versa as well.
G: S-> aSb|ε
S -> aSa|bSb|a|b
The language generated by the above grammar over the alphabet {a,b} is
the set of:
(A) All palindromes
(B) All odd length palindromes.
(C) Strings that begin and end with the same symbol
(D) All even length palindromes
S->aSb| ε
Key Points –
For a given language L(G), there can be more than one grammar
which can produce L(G).
The grammar G corresponding to language L(G) must generate all
possible strings of L(G).
The grammar G corresponding to language L(G) must not generate
any string which is not part of L(G).
It means either the string must contain one or more number of a OR one
or more number of b OR a followed by b having unequal number of a and
b.
S=>AC=>aAC=>aC=>ab
S=>aS=>ab
However, ab can’t be generated by language L. Therefore, grammar in
option (B) is not correct.
S=>AC=>C=>aCb=>ab
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Simplifying Context Free Grammars
The definition of context free grammars (CFGs) allows us to develop a
wide variety of grammars. Most of the time, some of the productions of
CFGs are not useful and are redundant. This happens because the
definition of CFGs does not restrict us from making these redundant
productions.
To remove useless productions , we first find all the variables which will
never lead to a terminal string such as variable ‘B’. We then remove all
the productions in which variable ‘B’ occurs.
So the modified grammar becomes –
We then try to identify all the variables that can never be reached from
the starting variable such as variable ‘C’. We then remove all the
productions in which variable ‘C’ occurs.
The grammar below is now free of useless productions –
After finding all the nullable variables, we can now start to construct the
null production free grammar. For all the productions in the original
grammar , we add the original production as well as all the combinations
of the production that can be formed by replacing the nullable variables in
the production by λ. If all the variables on the RHS of the production are
nullable , then we do not add ‘A -> λ’ to the new grammar. An example
will make the point clear. Consider the grammar –
Lets first find all the nullable variables. Variables ‘B’ and ‘C’ are clearly
nullable because they contain ‘λ’ on the RHS of their production. Variable
‘A’ is also nullable because in (2) , both variables on the RHS are also
nullable. Similarly , variable ‘S’ is also nullable. So variables ‘S’ , ‘A’ , ‘B’
and ‘C’ are nullable variables.
Lets create the new grammar. We start with the first production. Add the
first production as it is. Then we create all the possible combinations that
can can be formed by replacing the nullable variables with λ. Therefore
line (1) now becomes ‘S -> ABCd | ABd | ACd | BCd | Ad | Bd |Cd | d ’.We
apply the same rule to line (2) but we do not add ‘A -> λ’ even though it is
a possible combination. We remove all the productions of type ‘V -> λ’.
The new grammar now becomes –
First add all the non-unit productions of ‘G’ in ‘Guf’. Then for each
variable ‘A’ in grammar ‘G’ , find all the variables ‘B’ such that ‘A *=> B’.
Now , for all variables like ‘A ’ and ‘B’, add ‘A -> x1 | x2 | …xn’ to ‘Guf’
where ‘B -> x1 | x2 | …xn ‘ is in ‘Guf’ . None of the x1 , x2 … xn are single
variables because we only added non-unit productions in ‘Guf’. Hence
the resultant grammar is unit production free. For eg.
S -> Aa | B
A -> b | B
B -> A | a
Lets add all the non-unit productions of ‘G’ in ‘Guf’. ‘Guf’ now becomes –
S -> Aa
A -> b
B -> a
Now we find all the variables that satisfy ‘X *=> Z’. These are ‘S *=> A’ ,
‘S*=>B’, ‘A *=> B’ and ‘B *=> A’. For ‘A *=> B’ , we add ‘A -> a’ because ‘B
->a’ exists in ‘Guf’. ‘Guf’ now becomes
S -> Aa
A -> b | a
B -> a
For ‘B *=> A’ , we add ‘B -> b’ because ‘A -> b’ exists in ‘Guf’. The new
grammar now becomes
S -> Aa
A -> b | a
B -> a | b
We follow the same step for ‘S *=> A’ and ‘S*=>B’ and finally get the
following grammar –
S -> Aa | b | a
A -> b | a
B -> a | b
Kleene Closure : 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.
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.
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.
Let’s again take the above example in which L1 and L2 are same but
now let
L= L1 ∩ L2 which will easily result in
L={0^n1^n | n>=0} which is context-free .
You can take more such examples and verify that the union and
intersection of a regular language and a context-free language always
results in a context-free language.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Converting Context Free Grammar to
Chomsky Normal Form
Prerequisite – Simplifying Context Free Grammars
Note –
Step 3. Eliminate terminals from RHS if they exist with other terminals or
non-terminals. e.g,; production rule X->xY can be decomposed as:
X->ZY
Z->x
S → ASB
A → aAS|a|ε
B → SbS|A|bb
Step 2. As grammar contains null production A-> ε, its removal from the
grammar yields:
S0->S
S → ASB|SB
A → aAS|aS|a
B → SbS| A|ε|bb
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS| A|bb
Now, it creates unit production B->A, its removal from the grammar
yields:
S0->S
S → AS|ASB| SB| S
A → aAS|aS|a
B → SbS|bb|aAS|aS|a
Step 4: In production rule S0->ASB, RHS has more than two symbols,
removing it from grammar yields:
Similarly, S->ASB has more than two symbols, removing it from grammar
yields:
Similarly, A->XAS has more than two symbols, removing it from grammar
yields:
Similarly, B->SYS has more than two symbols, removing it from grammar
yields:
Similarly, B->XAX has more than two symbols, removing it from grammar
yields:
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Converting Context Free Grammar to
Greibach Normal Form
Prerequisite – Context Free Grammars, Simplifying Context Free
Grammars
S → XA|BB
B → b|SB
X → b
A → a
As G1 is already in CNF and there is not left recursion, we can skip step
1and 2 and directly move to step 3.
The production rule B->SB is not in GNF, therefore, we substitute S ->
XA|BB in production rule B->SB as:
S → XA|BB
B → b|XAB|BBB
X → b
A → a
S → bA|BB
B → b|bAB|BBB
X → b
A → a
S → bA|BB
B → bC|bABC
C → BBC| ε
X → b
A → a
S → bA|BB
B → bC|bABC|b|bAB
C → BBC|BB
X → b
A → a
S → bA| bCB|bABCB|bB|bABB
B → bC|bABC|b|bAB
C → BBC|BB
X → b
A → a
S → bA| bCB|bABCB|bB|bABB
B → bC|bABC|b|bAB
C → bCBC|bABCBC|bBC|bABBC
C → bCB|bABCB|bB|bABB
X → b
A → a
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Pumping Lemma
There are two Pumping Lemmas, which are defined for
1. Regular Languages, and
2. Context – Free Languages
If (1) and (2) hold then x = 0n1n2n = uvwxy with |vwx| ≤ n and |vx| ≥ 1.
(1) tells us that vwx does not contain both 0 and 2. Thus, either vwx has
no 0’s, or vwx has no 2’s. Thus, we have two cases to consider.
Suppose vwx has no 0’s. By (2), vx contains a 1 or a 2. Thus uwy has ‘n’
0’s and uwy either has less than ‘n’ 1’s or has less than ‘n’ 2’s.
But (3) tells us that uwy = uv0wx0y ∈ L.
So, uwy has an equal number of 0’s, 1’s and 2’s gives us a contradiction.
The case where vwx has no 2’s is similar and also gives us a
contradiction. Thus L is not context-free.
Derivation tree: It tells how string is derived using production rules from
S and has been shown in Figure 1.
Figure 1
Figure 2
but S => SS => SaSb => Sab => aSbab => abab is RMD but not LMD
Note:
I G is ambiguous
II G produces all strings with equal number of a’s and b’s
III G can be accepted by a deterministic PDA
Which combination below expresses all the true statements about G?
1. I only
2. I and III only
3. II and III only
4. I, II and III
Solution: There are different LMD’s for string abab which can be
Statement II states that the grammar G produces all strings with equal
number of a’s and b’s but it can’t generate aabb string. So statement II is
incorrect.
(B) is also correct as unambiguous CFG has a unique parse tree for each
string of the language generated by it.
Examples –
This is the example of operator grammar:
E->E+E/E*E/id
S->SAS/a
A->bSb/b
S->SbSbs/SbS/a
A->bSb/b
Since there is not any cycle in the graph so we can make function table:
fid -> g* -> f+ ->g+ -> f$
gid -> f* -> g* ->f+ -> g+ ->f$
#include <stdio.h>
#include <string.h>
void main()
{
char grm[20][20], c;
while (c != '\0') {
flag = 1;
else {
flag = 0;
f();
}
if (c == '$') {
flag = 0;
f();
}
c = grm[i][++j];
}
}
if (flag == 1)
printf("Operator grammar");
}
Input :3
A=A*A
B=AA
A=$
Output : Not operator grammar
Input :2
A=A/A
B=A+A
Advantages –
Disadvantages –
1. It is hard to handle tokens like the minus sign (-), which has two
different precedence (depending on whether it is unary or binary)
2. It is applicable only to small class of grammars
Pragati_Agrawal
Check out this Author's contributed articles.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Context-sensitive Grammar (CSG) and
Language (CSL)
Context-Sensitive Grammar –
A Context-sensitive grammar is an Unrestricted grammar in which all the
productions are of form –
Example –
Solution:
S → aAbc
→ abAc
→ abBbcc
→ aBbbcc
→ aaAbbcc
→ aabAbcc
→ aabbAcc
→ aabbBbccc
→ aabBbbccc
→ aaBbbbccc
→ aaabbbccc
The language generated by this grammar is {anbncn | n≥1}.
Practicing the following questions will help you test your knowledge. All
questions have been asked in GATE in previous years or in GATE Mock
Tests. It is highly recommended that you practice them.
References –
CSG – Wikipedia
CSG – csa.iisc.ernet.in
abhishek1
WorKing to be bEst veRsion of MySelf
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to
share more information about the topic discussed above.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Pushdown Automata
Pushdown Automata
We have already discussed finite automata. But finite automata can be
used to accept only regular languages.
Pushdown Automata is a finite automata with extra memory called stack
which helps Pushdown automata to recognize Context Free Languages.
δ( q0, a, Z ) = { ( q0, AZ ) }
δ( q0, a, A) = { ( q0, AA ) }
δ( q0, b, A) = { ( q1, ɛ) }
δ( q1, b, A) = { ( q1, ɛ) }
δ( q1, ɛ, Z) = { ( q1, ɛ) }
Note :
Solution : Every NFA can be converted into DFA. So, there expressive
power is same. As discussed above, every NPDA can’t be converted to
DPDA. So, the power of NPDA and DPDA is not same. Hence option (B)
is correct.
P = (Q, Σ, Γ, δ, q0, Z, F)
Here, from start state q0 and stack symbol Z, final state qf ɛ F is reached
when input w is consumed. The stack can contain string s which is
irrelevant as final state is reached and w will be accepted.
δ( q0, a, Z ) = { ( q1, AZ ) }
δ( q1, a, A) = { ( q1, AA ) }
δ( q1, b, A) = { ( q2, ɛ) }
δ( q2, b, A) = { ( q2, ɛ) }
δ( q2, ɛ, Z) = { ( q3, Z) }
After reading b (as shown in row 4), it will pop A and move to state q2
and stack will be AAZ. When all b’s are read, the state will be q2 and
stack will be Z. In row 7, on input symbol ɛ and Z on stack, it will move to
q3. As final state q3 has been reached after processing input, the string
will be accepted.
This type of acceptance is known as acceptance by final state.
Que-1. Consider the transition diagram of a PDA given below with input
alphabet ∑ = {a, b}and stack alphabet Γ = {X, Z}. Z is the initial stack
symbol. Let L denote the language accepted by the PDA. (GATE-CS-
2016)
Solution: We first label the state of given PDA as:
As there is only one move for a given state and input, the PDA is
deterministic. So, correct option is (D).
This article is contributed by Sonal Tuteja. If you like GeeksforGeeks and
would like to contribute, you can also write an article using
contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Construct Pushdown Automata for given
languages
Prerequisite – Pushdown Automata, Pushdown Automata Acceptance by
Final State
A push down automata is similar to deterministic finite automata except
that it has a few more properties than a DFA.The data structure used for
implementing a PDA is stack. A PDA has an output associated with every
input. All the inputs are either pushed into a stack or just ignored. User
can perform the basic push and pop operations on the stack which is use
for PDA. One of the problems associated with DFAs was that could not
make a count of number of characters which were given input to the
machine. This problem is avoided by PDA as it uses a stack which
provides us this facility also.
Examples:
Input : 0 0 1 1 1 2 2 2 3 3
Result : ACCEPTED
Input : 0 0 0 1 1 2 2 2 3 3
Result : NOT ACCEPTED
Examples:
Input : 0 0 0 1 1 1 1 1 1
Result : ACCEPTED
Input : 0 0 0 0 1 1 1 1
Result : NOT ACCEPTED
RishabhMalik
Check out this Author's contributed articles.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Construct Pushdown Automata for all
length palindrome
A Pushdown Automaton (PDA) is like an epsilon Non deterministic Finite
Automata (NFA) with infinite stack. PDA is a way to implement context
free languages. Hence, it is important to learn, how to draw PDA.
Examples:
Input : 1 0 1 0 1 0 1 0 1
Output :ACCEPTED
Input : 1 0 1 0 1 1 1 1 0
Output :NOT ACCEPTED
Examples:
Input : 1 0 0 1 1 1 1 0 0 1
Output :ACCEPTED
Input : 1 0 0 1 1 1
Output :NOT ACCEPTED
Now, take the example of all length palindrome, i.e. a PDA which can
accept both odd length palindrome and even length palindrome:
Que-3: Construct a PDA for language L = {ww’ | wcw’, w={0, 1}*} where
w’ is the reverse of w.
Examples:
Input : 1 1 0 0 1 1 1 1 0 0 1 1
Output :ACCEPTED
Input : 1 0 1 0 1 0 1
Output :ACCEPTED
AmishTandon
Check out this Author's contributed articles.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Turing Machine
Turing Machine
Turing Machine was invented by Alan Turing in 1936 and it is used to
accept Recursive Enumerable Languages (generated by Type-0
Grammar).
Illustration
Let us see how this turing machine works for 0011. Initially head points to
0 which is underlined and state is q0 as:
The move will be δ(q0, 0) = (q1, X, R). It means, it will go to state q1,
replace 0 by X and head will move to right as:
The move will be δ(q1, 0) = (q1, 0, R) which means it will remain in same
state and without changing any symbol, it will move to right as:
The move will be δ(q1, 1) = (q2, Y, L) which means it will move to q2
state and changing 1 to Y, it will move to left as:
Working on it in the same way, the machine will reach state q3 and head
will point to B as shown:
Note:
Question: A single tape Turing Machine M has two states q0 and q1, of
which q0 is the starting state. The tape alphabet of M is {0, 1, B} and its
input alphabet is {0, 1}. The symbol B is the blank symbol used to
indicate end of an input string. The transition function of M is described in
the following table.
Solution: Let us see whether machine halts on string ‘1’. Initially state will
be q0, head will point to 1 as:
It will run in the same way again and again and not halt.
Option D says M halts on all string ending with 1, but it is not halting for 1.
So, option D is incorrect.
Let us see whether machine halts on string ‘0’. Initially state will be q0,
head will point to 1 as:
It will run in the same way again and again and not halt.
Option C says M halts on all string ending with 0, but it is not halting for 0.
So, option C is incorrect.
Option B says that TM does not halt for any string (00 + 1)*. But NULL
string is a part of (00 + 1)* and TM will halt for NULL string. For NULL
string, tape will be,
Using δ(q0, B) = halt, TM will halt. As TM is halting for NULL, this option
is also incorrect.
So, option (A) is correct.
Examples –
Input : 0 0 1 1 1 1 0 0
Output : Accepted
Input : 1 0 1 0 0 1 0 1
Output : Accepted
Basic Representation –
Assumption: We will replace 0 by Y and 1 by X.
Approach Used –
First check the first symbol, if it’s 0 then replace it by Y and by X if it’s 1.
Then go to the end of string. So last symbol is same as first. We replace
it also by X or Y depending on it.
Now again come back to the position next to the symbol replace from the
starting and repeat the same process as told above.
Step-1:
If symbol is 0 replace it by Y and move right, Go to state Q2
If symbol is 1 replace it by X and move right, Go to state Q1
Step-2:
If symbol is 0 replace it by 0 and move right, remain on same state
If symbol is 1 replace it by 1 and move right, remain on same state
——————————————————————-
If symbol is X replace it by X and move right, Go to state Q3
If symbol is Y replace it by Y and move right, Go to state Q3
If symbol is $ replace it by $ and move right, Go to state Q3
Step-3:
If symbol is 1 replace it by X and move left, Go to state Q4
If symbol is 0 replace it by Y and move left, Go to state Q5
Step-4:
If symbol is 1 replace it by 1 and move left
If symbol is 0 replace it by 0 and move left
Remain on same state
Step-5:
If symbol is X replace it by X and move right
If symbol is Y replace it by Y and move right
Go to state Q0
Step-6:
If symbol is X replace it by X and move right
If symbol is Y replace it by Y and move right
Go to state Q6
ELSE
Go to step 1
Step-7:
If symbol is X replace it by X and move right, Remain on same state
If symbol is Y replace it by Y and move right, Remain on same state
If symbol is $ replace it by $ and move left, STRING IS ACCEPTED,
GO TO FINAL STATE Q7
RishabhMalik
Check out this Author's contributed articles.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Construct a Turing Machine for language
L = {ww | w ∈ {0,1}}
Prerequisite – Turing Machine
The language L = {ww | w ∈ {0, 1}} tells that every string of 0’s and 1’s
which is followed by itself falls under this language. The logic for solving
this problem can be divided into 2 parts:
Now our string would look like Y 0 1 1 0 Y. Now move left till, find a X or
Y. When we do so, convert the 0 or 1 right of it to X or Y respectively and
then do the same on right end. Now our string would look like Y X 1 1 X
Y. Thereafter, convert these 1’s also and finally it would look like Y X Y Y
X Y.
At this point you have achieved first objective which was to find the mid
point. Now convert all X and Y on the left of mid point into 0 and 1
respectively, so string becomes 1 0 1 Y X Y. Now, convert the 1 into Y
and move right till, find Y in the beginning of right part of string and
convert this Y into a blank (denoted by B). Now string looks like Y 0 1 B X
Y.
Similarly, apply this on 0 and x followed by 1 and Y. After this string looks
like Y X Y B B B. Now that you have no 0 and 1 and all X and Y on right
part of string are converted into blanks so our string will be accepted.
Approach Used –
The first thing is to find the mid point of the string, convert a 0 or 1 from
the beginning of the string into X or Y respectively and a corresponding 0
or 1 into X or Y from the end of the string. After continuously doing it a
point is reached when all 0’s and 1’s have been converted into X and Y
respectively. At this point you are on the mid point of the string. So, our
first objectively is fulfilled.
Now, convert all X’s and Y’s on the left of the mid point into 0’s and 1’s. At
this point the first half the string is in the form of 0 and 1. The second half
of the string is in the form of X and Y.
Now, start from the beginning of the string. If you have a 0 then convert it
into X and move right till reach the second half, here if we find X then
convert it into a blank(B). Then traverse back till find an X or a Y. We
convert the 0 or 1 on right of it into X or Y respectively and
correspondingly, convert its X or Y in the second half of string into a
blank(B).
Keep doing this till, converted all symbols on left part of string into X and
Y and all symbols on right of string into blanks. If any one part is
completely converted but still some symbols in other half are left
unchanged then string will not be accepted. If you did not find an X or Y
in second half for a corresponding 0 or 1 respectively in the first half.
Then also string will not be accepted.
Examples:
Input : 1 1 0 0 1 1 0 0
Output : Accepted
Input : 1 0 1 1 1 0 1
Output : Not accepted
Step-1:
If symbol is 0 replace it by X and move right
If symbol is 1 replace it by Y and move right,
Go to state Q1 and step 2
———————————————
If symbol is X replace it by X and move left or
If symbol is Y replace it by Y and move left,
Go to state Q4 and step 5
Step-1:
If symbol is 0 replace it by 0 and move right, remain on same state
If symbol is 1 replace it by 1 and move right, remain on same state
———————————————
If symbol is X replace it by X and move left or
If symbol is Y replace it by Y and move left or
If symbol is $ replace it by $ and move left, Go to state Q2 and step 3
Step-1:
If symbol is 0 replace it by X and move left, or
If symbol is 1 replace it by Y and move left,
Go to state Q3 and step 4
Step-1:
If symbol is 0 replace it by 0 and move left, remain on same state
If symbol is 1 replace it by 1 and move left, remain on same state
———————————————
If symbol is X replace it by X and move right or
If symbol is Y replace it by Y and move right,
Go to state Q0 and step 1
Step-1:
If symbol is X replace it by X and move left or
If symbol is Y replace it by Y and move left
Go to state Q4 and step 6
Step-1:
If symbol is X replace it by 0 and move left, remain on same state
If symbol is Y replace it by 1 and move left, remain on same state
–––––––––—–––––––––—
If symbol is $ replace it by $ and move right
Go to state Q4 and step 7
Step-1:
If symbol is 0 replace it by X and move right, go to state Q6 and step
8
If symbol is 1 replace it by Y and move right, go to state Q7 and step
9
–––––––––—–––––––––—
If symbol is B replace it by B and move left, STRING ACCEPTED, GO
TO FINAL STATE Q9
Step-1:
If symbol is 0 replace it by 0 and move right, remain on same state
If symbol is 1 replace it by 1 and move right, remain on same state
If symbol is B replace it by B and move right, remain on same state
–—––––––––––––––––––
If symbol is X replace it by B and move left
Go to state Q8 and step 10
Step-1:
Step-1:
If symbol is 0 replace it by 0 and move left, remain on same state
If symbol is 1 replace it by 1 and move left, remain on same state
If symbol is B replace it by B and move left, remain on same state
–—––––––––––––––––––
If symbol is Y replace it by Y and move right or
If symbol is X replace it by X and move right
Go to state Q5 and step 7
RishabhMalik
Check out this Author's contributed articles.
If you like GeeksforGeeks and would like to contribute, you can also write
an article using contribute.geeksforgeeks.org or mail your article to
[email protected]. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Recursive and Recursive Enumerable
Languages
Recursive Enumerable (RE) or Type -0 Language
L1= {anbncn|n>=0}
L2= {dmemfm|m>=0}
L3= L1.L2
= {anbncndm emfm|m>=0 and n>=0} is also recursive.
L1= {anbncn|n>=0}
L1*= { anbncn||n>=0}* is also recursive.
GATE Questions
A.1 and 4
B.1 and 3
C.2
D.3
Solution:
Undecidable Problems –
The problems for which we can’t construct an algorithm that can answer
the problem correctly in a finite time are termed as Undecidable
Problems. These problems are not even partially decidable and can lead
a Turing machine to loop forever without answering at all.
GATE CS
Theory of Computation & Automata
Please write to us at [email protected] to report any issue
with the above content.
Decidability
Identifying languages (or problems*) as decidable, undecidable or
partially decidable is a very common question in GATE. With correct
knowledge and ample experience, this question becomes very easy to
solve.
For eg.
Now lets try to reduce the Halting problem to the State Entry problem. A
Turing machine only halts when a transition function δ (qi , a) is not
defined. Change every undefined function δ(qi,a) to δ(qi,a) = (Q, a, L or
R). Note that the state Q can only be reached when the Turing machine
halts.
Suppose we have have an algorithm for solving the State Entry problem
which will halt every time and tell us whether state Q can be reached or
not. By telling us that we can or cannot reach state Q every time, it is
telling us that the Turing machine will or will not halt, every time. But we
know that is not possible because the halting problem is undecidable.
That means that our assumption that there exists an algorithm which
solves the State Entry problem and halts and gives us an answer every
time, is false. Hence, the state entry problem is undecidable.
First we make two Turing machines TM1 and TM2 which simulate the
DFAs of languages L1 and L2 respectively. We know that a DFA always
halts, so a Turing machine simulating a DFA will also always halt. We
enter the string ‘w’ in TM1 and TM2. Both Turing machines will halt and
give us an answer. We can connect the outputs of the Turing machines to
a modified ‘AND’ gate which will output ‘yes’ only when both the Turing
machines answer ‘yes’. Otherwise it will output ‘no’.
Since this system of two Turing machines and a modified AND gate will
always stop, this problem is a decidable problem.
There are a lot of questions on this topic. There is no universal algorithm
to solve them. Most of the questions require unique and ingenious proofs.
Here is where experience is needed. By solving a lot of these problems,
one can become very quick in coming up with proofs for these problems
on the spot. So, keep practicing.
Decidable Problems
A problem is decidable if we can construct a Turing machine which will
halt in finite amount of time for every input and give answer as ‘yes’ or
‘no’. A decidable problem has an algorithm to determine the answer for a
given input.
Examples
Undecidable Problems
A problem is undecidable if there is no Turing machine which will always
halt in finite amount of time to give answer as ‘yes’ or ‘no’. An
undecidable problem has no algorithm to determine the answer for a
given input.
Examples
Ambiguity of context-free languages: Given a context-free
language, there is no Turing machine which will always halt in finite
amount of time and give answer whether language is ambiguous or
not.
Equivalence of two context-free languages: Given two context-free
languages, there is no Turing machine which will always halt in finite
amount of time and give answer whether two context free languages
are equal or not.
Everything or completeness of CFG: Given a CFG and input
alphabet, whether CFG will generate all possible strings of input
alphabet (∑*)is undecidable.
Regularity of CFL, CSL, REC and REC: Given a CFL, CSL, REC or
REC, determining whether this language is regular is undecidable.
w ɛ A <=> f(w) ɛ B
1. G is a CFG. Is L(G)=ɸ?
2. G is a CFG. Is L(G)=∑*?
3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A)=L(N)?
A. 3 only
B. 3 and 4 only
C. 1, 2 and 3 only
D. 2 and 3 only
Explanation:
A. 1,2,3,4
B. 1,2
C. 2,3,4
D. 3,4
Explanation:
A. P3 is undecidable if P2 is reducible to P3
B. P3 is decidable if P3 is reducible to P2’s complement
C. P3 is undecidable if P3 is reducible to P2
D. P3 is decidable if P1 is reducible to P3
Explanation:
Quiz on Undecidability
This article is contributed by Sonal Tuteja. Please write comments if you
find anything incorrect, or you want to share more information about the
topic discussed above
We will discuss the important key points useful for GATE exams in
summarized form. For details you may refer this.
Turing Machine :Turing machine has infinite size tape and it is used
to accept Recursive Enumerable Languages.
Turing Machine can move in both directions. Also, it doesn’t accept
ε.
If the string inserted in not in language, machine will halt in non-
final state.
α→β where α,
Type-1 β (T N)* Union,
and len(α) <= Linear Intersection,
(Context Context
len(β) and α Bound Complementa
Sensitive Sensitive
should contain Automata Concatenation
Grammar)
atleast 1 non Kleene Closur
terminal.
α → β where α,
Type-0 β (T N)*
Recursive Turing
(Recursive and α contains
Enumerable) atleast 1 non- Enumerable Machine Concatenatio
terminal Kleene Closu
Countability :
Set of all strings over any finite alphabet are countable.
Every subset of countable set is either finite or countable.
Set of all Turing Machines are countable.
The set of all languages that are not recursive enumerable is
Uncountable.