You are on page 1of 37

TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)

Glorious Academy www.gloriousacademy.org


Q1 a) Define the following terms
1) Undecidability:
An undecidable problem is a problem
leads to a correct yes-or-no answer.
Examples of undecidable problem
- the halting problem is a decision problem
Given the description of an arbitrary
running or will run forever.
- Determining if a context-free grammar
undecidable problem.
ii) Unrestricted Grammar :
Unrestricted grammar is a formal grammar
grammar's productions. This is the most general class of grammars in the
An unrestricted grammar is a formal grammar
symbols, is a set of terminal symbols
are strings of symbols in and
symbol. As the name implies, there are no real restrictions on the types of production rules that
grammars can have.
iii) Pumping Lemma
Pumping Lemma is used for proving that a language is
L = {a
n
b
n
/ n >=1 } is not regular can be proved by using pumping lemma. The formal statement of pumping
lemma is as follows :
Let L be a regular language. Then there exists an integer
called the "pumping length") can be written as
following conditions:
1. |y| 1;
2. |xy| p
3. for all i 0, xy
i
z L
y is the substring that can be pumped (removed or repeated any number of times, and the resulting
always in L). (1) means the loop y to be pumped must be of length at least one; (2) means the loop must occur
within the first p characters. |x| must be smaller than
restriction on x and z.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
May 2013
problem for which it is impossible to construct a single algorithm
decision problem which can be stated as follows:
Given the description of an arbitrary program and a finite input, decide whether the program finishes
free grammar generates all possible strings, or if it is ambiguous.
formal grammar on which no restrictions are made on the left and right sides
grammar's productions. This is the most general class of grammars in the Chomsky hierarchy
formal grammar , where is a set of nonterminal
terminal symbols. is a set of production rules of the form
and is not the empty string, and is a specially designated start
symbol. As the name implies, there are no real restrictions on the types of production rules that
Pumping Lemma is used for proving that a language is not regular. For example the language
=1 } is not regular can be proved by using pumping lemma. The formal statement of pumping
be a regular language. Then there exists an integer p such that every string w in L of length at least
h") can be written as w = xyz (i.e., w can be divided into three substrings), satisfying the
is the substring that can be pumped (removed or repeated any number of times, and the resulting
to be pumped must be of length at least one; (2) means the loop must occur
| must be smaller than p (conclusion of (1) and (2)), apart from that there is no
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 1
algorithm that always
and a finite input, decide whether the program finishes
if it is ambiguous. Is
on which no restrictions are made on the left and right sides of the
Chomsky hierarchy,
is a set of nonterminal
where and
is a specially designated start
symbol. As the name implies, there are no real restrictions on the types of production rules that unrestricted
. For example the language
=1 } is not regular can be proved by using pumping lemma. The formal statement of pumping
of length at least p (p is
can be divided into three substrings), satisfying the
is the substring that can be pumped (removed or repeated any number of times, and the resulting string is
to be pumped must be of length at least one; (2) means the loop must occur
(conclusion of (1) and (2)), apart from that there is no
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 2
In simple words, for any regular language L, any sufficiently long word w (in L) can be split into 3 parts. i.e. w =
xyz , such that all the strings xy
k
z for k0 are also in L.
Q1 b) Define TM and its variants
Definition
Conceptually a Turing machine, like finite automata, consists of a finite control and a
tape. At any time it is in one of the finite number of states. The tape has the left end
but it extends infinitely to the right. It is also divided into squares and a symbol can be
written in each square. However, tape of the turing machine has a read-write head
and it can move left, right or stay at the same square after a read or write.
Working of Turing machine
Given a string of symbols on the tape, a Turing machine starts at the initial state. At
any state it reads the symbol under the head, either erases it or replaces it with a
symbol (possibly the same symbol). It then moves the head to left or right or does not
move it and goes to the next state which may be the same as the current state. One of
its states is the halt state and when the Turing machine goes into the halt state, it
stops its operation.
Formally
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 3
A Turing machine is a 5-tuple T = < Q, , , q
0
, > , where
Q is a finite set of states, which is assumed not to contain the symbol h. The symbol
h is used to denote the halt state.
is a finite set of symbols and it is the input alphabet.
is a finite set of symbols containing as its subset and it is the set of tape
symbols.
q
0
is the initial state.
is the transition function but its value may not be defined for certain points.
It is a mapping from
Q X ( ) to ( Q ) X ( ) X { R , L , S } .
Here R, L and S denote move the head right, left and do not move it, respectively.
A transition diagram can also be drawn for a Turing machine. The states are
represented by vertices and for a transition ( q, X ) = ( r, Y, D ) , where D
represents R, L or S , an arc from q to r is drawn with label ( X/Y , D ) indicating that
the state is changed from q to r, the symbol X currently being read is changed to Y
and the tape head is moved as directed by D.
Variants of Turing machine
Variations of TM
1) Stay option turing machine
2) Semi infinite tape turing machine
3) Off Line turing machine
4) Multi tape turing machine
5) Multidimensional turing machine
6) Nondeterministic turing
Q1 c) Chomsky hierarchy for formal languages
The Chomsky hierarchy is a way of classifying formal grammars into four types
The Chomsky hierarchy consists of the following levels:
Type-0 grammars (unrestricted grammars) include all formal grammars. They
generate exactly all languages that can be recognized by a Turing machine.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org
These languages are also known as the
Note that this is different from the
be decidedby an always-
Type-1 grammars (context
languages. These grammars have rules of the form
nonterminal and , and
strings and may be empty, but
allowed if does not appear on the right side of any rule. The languages
described by these grammars are exactly all languages that can be recognized
by a linear bounded automaton
tape is bounded by a constant times the length of the input.)
Type-2 grammars (context
languages. These are defined by rules of the form
nonterminal and a string of terminals and nonterminals. These
are exactly all languages that can be recognized by a non
deterministic pushdown automaton
theoretical basis for the syntax of m
Type-3 grammars (regular grammars
grammar restricts its rules to a single nonterminal on the left
right-hand side consisting of a single terminal, possibly followed (or precede
but not both in the same grammar) by a single nonterminal. The rule
also allowed here if does not appear on the right side of any rule. These
languages are exactly all languages that can be decided by a
automaton. Additionally, this family of formal languages can be obtained
by regular expressions. Regular
patterns and the lexical structure of programming languages.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
These languages are also known as the recursively enumerable languages
Note that this is different from the recursive languages which can
-halting Turing machine.
context-sensitive grammars) generate the context
. These grammars have rules of the form
and strings of terminals and nonterminals. The
may be empty, but must be nonempty. The rule
does not appear on the right side of any rule. The languages
described by these grammars are exactly all languages that can be recognized
linear bounded automaton (a nondeterministic Turing machine whose
tape is bounded by a constant times the length of the input.)
context-free grammars) generate the context-
. These are defined by rules of the form with
a string of terminals and nonterminals. These
are exactly all languages that can be recognized by a non-
pushdown automaton. Context-free languages are the
theoretical basis for the syntax of most programming languages.
regular grammars) generate the regular languages
grammar restricts its rules to a single nonterminal on the left-hand side and a
hand side consisting of a single terminal, possibly followed (or precede
but not both in the same grammar) by a single nonterminal. The rule
does not appear on the right side of any rule. These
languages are exactly all languages that can be decided by a finite state
. Additionally, this family of formal languages can be obtained
. Regular languages are commonly used to define search
patterns and the lexical structure of programming languages.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 4
recursively enumerable languages.
which can
context-sensitive
with a
strings of terminals and nonterminals. The
ule is
does not appear on the right side of any rule. The languages
described by these grammars are exactly all languages that can be recognized
(a nondeterministic Turing machine whose
-free
a
a string of terminals and nonterminals. These languages
free languages are the
.
regular languages. Such a
hand side and a
hand side consisting of a single terminal, possibly followed (or preceded,
but not both in the same grammar) by a single nonterminal. The rule is
does not appear on the right side of any rule. These
finite state
. Additionally, this family of formal languages can be obtained
languages are commonly used to define search
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org
Grammar Languages
Type-0 Recursively enumerable Turing machine
Type-1 Context-sensitive Linear-bounded non
Type-2 Context-free Non-deterministic
Type-3 Regular Finite state automaton
Q1 d) Closure properties of Regular
If L1 and L2 are two different regular languages then
a) Union of the two languages L1 and L2 (L1 U L2) is also regular.
b) Intersection of two languages L1 and L2 (L1
c) Complement of both the languages (~L1 and ~L2 ) i
d) Reversal of a regular language is also regular.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
Automaton Production rules (constraints)
Turing machine
(no restrictions)
bounded non-deterministic Turing machine
deterministic pushdown automaton
Finite state automaton and
Q1 d) Closure properties of Regular languages.
If L1 and L2 are two different regular languages then
a) Union of the two languages L1 and L2 (L1 U L2) is also regular.
b) Intersection of two languages L1 and L2 (L1 L2) is also regular.
c) Complement of both the languages (~L1 and ~L2 ) is also regular.
d) Reversal of a regular language is also regular.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 5
Production rules (constraints)
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 6
For example
let L1 = {a,aa,aaa,aaaa,aaaaa,} Clearly L1 is regular language and can be written as
L1 = {a
n
/ n>=1 }
Let L2 = {b,bb,bbb,bbbb,bbbbb,..} Clearly L2 is regular language and can be written as
L2 = {b
n
/ n>=1 }
Then
L1 U L2 = {a,aa,aaa,aaa, , b,bb,bbb,bbbb, } is union of both languages and is written as
L1 U L2 = {a
n
| b
n
/ n>=1}
Q2 a) What is ambiguous CFG. Give one example of ambiguous CFG
An ambiguous grammar is a formal grammar for which there exists a string that can have more than
one leftmost derivation, while an unambiguous grammar is a formal grammar for which every valid
string has a unique leftmost derivation.
The context free grammar
A A + A | A A | a
is ambiguous since there are two leftmost derivations for the string a + a + a:
LeftMost Derivation 1
A -> A + A
a + A
a + A + A
a + a + A
a + a + a which is the required string
LeftMost Derivation 2
A -> A + A
A + A + A
a + A + A
a + a + A
a + a + a which is the required string
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 7
Clearly there are 2 leftmost derivations for the string a+a+a. Hence the grammar
is ambiguous.
As another example, the grammar is ambiguous since there are two parse trees for the string a +
a a:
Q 2 b) Let G be a CFG, find leftmost, rightmost derivations and parse tree for a string 00110101
S -> 0B | 1A
A -> 0 | 0S | 1AA
B -> 1 | 1S | 0BB
Leftmost Derivation of 00110101
S -> 0B
00BB using rule B->0BB
001B using rule B->1
0011S using rule B->1S
00110B using rule S->0B
001101S using rule B->1S
0011010B using rule S->0B
00110101 using rule B->1
Rightmost Derivation of 00110101
S -> 0B
00BB using rule B -> 0BB
00B1 using rule B->1
001S1 using rule B->1S
0011A1 using rule S->1A
00110S1 using rule A->0S
001101A1 using rule A->1A
00110101 using rule A->0
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 8
Parse Tree for derivation of 00110101
S
0 B
0 B B
1 1 S
0 B
1 S
0 B
1
Q3 a) Explain CNF and GNF with examples
Chomsky Normal Form : A context free grammar is in Chomsky Normal Form (CNF) if every rule is of the
form
A -> BC or
A -> a
Where a is a terminal and A,B,C are nonterminals.
For example : The given grammar is in CNF
S -> AB | BC rule 1
A -> AB | a rule 2
B -> BA | b rule 3
C -> c rule 4
Greibach Normal Form : A context free grammar is in Greibach Normal Form (GNF) if every rule is of the
form
A -> a or
A -> a
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 9
Where a is a terminal and A is a nonterminal and is list of nonterminals . = (N)*
For example : The given grammar is in GNF
S -> aAB | bBC rule 1
A -> aAB | a rule 2
B -> bBA | b rule 3
C -> c rule 4
Q 3 b) Give formal definition of RE and design DFA for regular expression (a+b)* aba (a+b)*
Formal definition of RE
Regular expression is a method used to specify Regular Language. Regular expression over an
alphabet can be defined as
a) every symbol a of is a regular expression
b) (empty string) is a regular expression
c) if r1 and r2 are regular expressions than
r1 + r2 is a regular expression (ORing)
r1 . r2 is a regular expression (Concatenation)
r1* is a regular expression (Kleenes closure)
Given RE is
(a + b)* aba (a+b)*
To construct DFA we need 2 steps
Step 1 : Draw NFA for given RE
Step 2 : Convert NFA into equivalent DFA
Step 1 : Draw NFA for given RE
This NFA has following transition table
Q\E a b
q
0
{ q
0
, q
1
} { q
0
}
q
1
{ } { q
2
}
q
2
{ q
3
} { }
q
3
{ q
3
} { q
3
}
q

q
q

a
b a
a, b
a, b
q
3
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 10
Step 2 : Convert NFA to DFA
(a) Initial state of DFA is same as initial state of NFA q
0
(b) Find out transitions for symbol a and b for state q

.
o (q

, a) = { q

, q

} This is a new state of DFA
o (q

, b) = { q

}
(c) Find out transitions for symbols a & b for state q

q


o ( q

q

a

) = o ( q

, a

) U o ( q

a

)
o ( q

q

a

) = ( q

, q

) U { }


o ( q

q

a

) = { q

, q

}
AND

o ( q

q

b

) = o ( q

, b

) U o ( q

b

)
o ( q

q

b

) = {q

} U { q
2
}


o ( q

q

b

) = { q

, q

} Now state of DFA
(d) Find out transitions for state q

q

for symbols a & b
o ( q

q
2
a

) = o ( q

, a

) U o ( q
2
a

)
o ( q

q
2
a

) = {q

, q
1
} U { q
3
}


o ( q

q
2
a

) = { q

, q
1,
q
3
} Now state of DFA
AND
o ( q

q
2
b

) = o ( q

, b

) U o ( q
2
b

)
o ( q

q
2
b

) = {q

} U { }


o ( q

q
2
b

) = { q

}
q

q

q

a
b
q

q

q

q

q

a
b
b a
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 11
(e) Find out transitions for state q

q

q
3
for symbols a and b
o ( q

q
1
q
3,
a

) = o ( q

, a

) U o ( q
1
a

) U o ( q
3
a

)
o ( q

q
1
q
3,
a

) = { q

, q

} U {

} U { q
3
}

o ( q

q
1
q
3,
a

) = { q

, q
1,
q
3
}
AND
o ( q

q
1
q
3,
b

) = o ( q

, b

) U o ( q
1
b

) U o ( q
3
b

)
o ( q

q
1
q
3,
b

) = { q

} U { q
2
} U { q
3
}

o ( q

q
1
q
3,
b

) = { q

, q
2,
q
3
} New state
(f) Find out transitions for state q

q
2
q
3
for symbols a and b
o ( q

q
2
q
3,
a

) = o ( q

, a

) U o ( q
2
a

) U o ( q
3
a

)
o ( q

q
2
q
3,
a

) = { q

, q

} U {

q
3
} U { q
3
}

o ( q

q
2
q
3,
a

) = { q

, q
1,
q
3
}
q

q

q
q

q

a
b a
b
q

q

q

b
a
q

q

q
q

q

a
b a
q

q

b
q

q

b
b
a
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 12
AND
o ( q

q
2
q
3,
b

) = o ( q

, b

) U o ( q
2
b

) U o ( q
3
b

)
o ( q

q
2
q
3,
b

) = { q

} U { } U { q
3
}

o ( q

q
2
q
3,
b

) = { q

, q
3
} New state of DFA
(g) Find out transitions for state q

q
3
o ( q

q
3,
a

) = o ( q

, a

) U o ( q
3
a

)
o ( q

q
3,
a

) = o { q

, q

} U ( q
3
)

o ( q

q
3,
a

) = { q

, q
1,
q
3
}
AND
o ( q

q
3,
b

) = o ( q

, b

) U o ( q
3
b

)
o ( q

q
3,
b

) = o { q

} U {q
3
}

o ( q

q
3,
b

) = { q

, q
3
}
Now there are no more new states. Hence the final NFA.
The final states of DFA are those states which contain q
3
state of NFA.
a
a
b
q

q

q
q

q

a
b a
b
b
a
q

q

q

q

b
a
b
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 13
Q 3 c) Using pumping Lemma prove that following language is not regular
L = {a
n
b
n
/ n >= 1}
1. Let L be regular. Then there exists a DFA which will accept this language. Let P be the
pumping length
2. Choose a string w = a
p
b
p
. Clearly |w| >= p
3. Decompose w into xyz, but since |xy| <= p, xy must consist entirely of a's. Moreover, y
cannot be empty(ie |y| > 0). Let us assume that y = a.
4. Choose i = 2. This has the effect of adding one more a, without affecting the number of
b's. The resultant string has more a's than b's, hence does not belong to L. Therefore L is
not regular.
Q 4 a) Write NFA to accept following language
(a + bb)* (ba* + )
Step (a) Let us consider (a + bb)*

NFA for a is
NFA for bb is
Step b : Now we can show NFA for (a + bb) as
a
b
b
a
b b
c
c
c
c
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 14
Step c : NFA for (a + bb)* will be
Step d : Now consider (ba* + c )





NFA for b NFA for a*
NFA for (b a*) with be concatenation of NFA of b & NFA of a*
b
c
c
c a
c
c
c
c a b
c
a
b
b
c
c
c
c
c
c
c
c
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 15
Step e : NFA for (ba* + c) is
Step f : Finally NFA for entire RE (a + bb*) (ba* + c) will be concatenation of step c & step e.
Q5 a) Find out the languages defined by the following grammar
The grammar recoginizes all strings with even number of 1s and odd number of 0s.
The derivation of any string must start at start symbol S. This symbol can derive 0A or 1C. Note that only
A can be substituted with E symbol. Hence smallest string that can be derived from the above grammar
is 0.
S -> 0A
0
Clearly this string has odd 0s.
c
c c
c
c
c
c
c
c
c
c
c
c
c
c
c a b
c
c
c
c
c
c
c
c
c
c
a
b b
c
c
c
c
b c
a c
c
c

c
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 16
On the other hand , suppose we use S -> 1C as the first point in the derivation. Then there is no way to
terminate the derivation except by bringing A into our derivation which necessarily brings odd number
of 0s.
As other Example :
consider derivation of string 1111011
S -> 1C
11S
111C
1111S
11110A
111101B
1111011A
1111011
Clearly this string has even number of 1s and odd number of 0s.
ii)
S -> 0A | 1C
A -> 0S | 1B
B -> 0C | 1A |
C -> 0B | 1S
This grammar accepts all strings with odd number of 1s and odd number of 0s.
(Left as exercise to prove)
Q 5 b) Design PDA to accept language
L = {a
n
b
m
a
n
| m,n >= 1}
The push Down automata M is 7 tuple
M = ( Q, E, I, o, q
0
, z
0
, F )
For the language L =
{ }
>=
n m n
a b a |m,n 1
We have
E = { a, b }
The stack of PDA will store X for every a. The initial stack symbol is z
0
.
Hence I = { X, z
0
}
The idea = To recognize the language L =
{ }
>=
n m n
a b a |m,n 1
We will push one X in the stack when ever PDA reads a.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 17
For example if the string w = aabbbaa. Then after reading first 2 a s the stack will be
X 2 X for 2 as
X
Z
0
initial stack symbol
Now for the next 3 bs our PDA will not change the stack. In other words we will ignore or skip all
bs.
Finally for last 2 as we will pop one X for every a
Hence the stack will contain only Z
0
at the end of process. Which means that number of as In the
begining are equal to number of as at the end.
The state diagram for PDA is
The PDA M has
Q = { q
0
, q
1
, q
2
, q
3
}
q
0
= initial state
E = { a, b }
I = { X, Z
0
}
Z
0
= initial stack symbol.
F = { q
3
} final state
o : transition function is
o : ( q
0
, a, Z
0
) = ( q
0
, XZ
0
)
o : ( q
0
, a, X ) = ( q
0
, XX )
o : ( q
0
, b, X ) = ( q
1
, X )
o : ( q
1
, b, X ) = ( q
1
, X )
o : ( q
1
, a, X) = ( q
0
, )
o : ( q
2
, a, X) = ( q
2
, )
o : ( q
2
, , Z
0
) = ( q
3
, Z
0
)
a, X / c
q

q
q

b, X / X
a, X / c
a, Z
0
/ XZ
0
b, X / X
q

c, Z
0
/ Z
0
a, X / XX
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 18
Working of this PDA can be shown by considering string w = aabbbaa. The initial state of PDA is
q
0
and initial stack symbol is
( q
0
aabbbaa, Z
0
)
( q
0
aabbbaa, XZ
0
)
( q
0
aabbbaa, XXZ
0
)
( q
1
aabbbaa, XXZ
0
)
( q
1
aabbbaa, XXZ
0
)
( q
1
aabbbaa, XXZ
0
)
( q
2
aabbbaa, XZ
0
)
( q
2
aabbbaa_, Z
0
)
( q
3
aabbbaa_, Z
0
)
q
3
is the, final state & the i/p is over. Therefore string aabbbaa is valid & accepted.
Q 6 a) Differentiate between Mealy and Moore machine with proper example. Carry out conversion of
Moore MIC to Mealy MIC
Difference between Mealy and Moore Machine
Moore Machine Mealy Machine
1 It is FSM in which output depends only on
the current state.
It is FSM in which output depends on the
current state, and current input
2. For a Moore Machine M=(Q,E, o, , q

,I)
Where
Q= finite set of states.
E =Finite set of i/p symbol
o = Transfer function
o: Q x E Q
=output function
: Q I

q
0
= Initial State
I = finite set of output symbols
For a Mealy Machine M=(Q,E, o, , q

,I)
Where
Q= finite set of states.
E =Finite set of i/p symbol
o = Transfer function
o: Q x E Q
=output function
: Q x E I

q
0
= Initial State
I = finite set of output symbols
3. If the input given to Moore machine has n
symbols, then output of Moore machine has n+1
symbols. Therefore length of output is one more
then length of input
If the input given to mealy machine has n
symbols, then output of mealy machine has n
symbols. Therefore length of output equal to
length of the input.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 19
Following Moore machine which with output A if input ends 11, output B if input
ends with 10 output C otherwise.
The equivalent Mealy machine is
Q 6 b) Design a Turing machine that accepts the language L = {a
n
b
n
| n >= 1}
TM = ( Q , I, o, B, F )
Where = { a, b }
I = { X, , B, a, b } ( tape symbols)
The idea : every a will be over written as X and every b will be over written as .
The TM will do multiple scans of the input (from left to right and right to left) as follows
B a a b b B
|
X
Replace first a with X and move forward till we get first b
1/A
1
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 20
B X a b b B
|
y
Replace b with y & move backward till we get X. On reaching X move one symbol right & change
a to X.
B X a y b B
|
X
This process goes on till all as are changed to X & b s are changed to y. finally the TM will check if
there are any pending a or bs.
Q7 Write short note on ant four
a) Recursive and Recursively enumerable language
Recursive and Recursively enumerable languages
Recursively Enumerable Languages
A TM accepts a string w if the TM halts in a final state. A TM rejects a string w if the TM halts in a
nonfinal state or the TM never halts.
A language L is recursively enumerable if some TMaccepts it.
A language L is recursive if some TM accepts it and halts on every input. Note: the complement of
a recursive language is also recursive.
L is recursive implies L is recursively enumerable.
q

q
q

a / XR
b/ YL
q
q

Y / YR
a / aR
Y/YR
a / aL
Y / YL
Y / YR
B / BS
X/ XR
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 21
The Halting problemis r.e. but not recursive. Indeed one can run the Turing Machine and accept
if the machine halts, hence it is r.e. On the other hand the problem is undecidable.
Some other r.e. language that are not recursive :
post correspondance problem
Travelling salesman problem
Satisfiability problem
b) Intractable Problem
A problem is called Intractable if all algorithms to solve it take exponential time instead of
polynomial time.
Example: the Towers of Hanoi
Consider the following problem:
Move the three rings, which are piled up in descending order of magnitude, from peg A to peg
C, possibly using peg B in the process, moving rings one at a time, and at no time allowing a
larger ring to rest on top of a smaller one
The puzzle above has the solution:
move topmost ring from A to C;
move topmost ring from A to B;
move topmost ring from C to B;
move topmost ring from A to C;
move topmost ring from B to A;
move topmost ring from B to C;
move topmost ring from A to C;
Note that for number of rings = 3 , the total number of moves necessary = 7
Which can be written as 2
rings-1
.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 22
We cant just imagine solving this puzzle if number of rings were in a large number. for example
if number of rings = 64 then the number of moves = 2
64
- 1.
c) Simplication of CFG
CFG can be simplified by
i) Eliminating useless symbols
ii) Eliminating E-productions
iii) Eliminating Unit-productions
Eliminating Useless Symbols from a CFG
- A symbol X is useful for a CFG if there is a derivation of the form S
*
X
*
w for
some string of terminals w. In other words we say that X is useful if we can derive some
terminal string w from X.
- If X is not useful, then we say X is useless. Such useless symbols can be removed from
CFG. The modified CFG will also generate the same language as the original CFG.
- Symbol X is useful if
1. X can be used to derive some string of terminals.
2. X must be reachable; that is, there needs to be a derivation of the form S
*
X
where and are strings of nonterminals and terminals.
- To eliminate useless symbols from a grammar, we
1. identify the non generating symbols (that is symbols which do not generate
terminal string w) and eliminate all productions containing one or more of these
symbols, and then
2. eliminate all productions containing symbols that are not reachable from the
start symbol.
- In the grammar
S AB | a
A b
We see that S a. So S is a generating symbol because S derives terminal a.
We see that A b. So A is a generating symbol because A derives terminal b.
But B does not derive any terminal string directly or indirectly.
S, A are generating. B is not generating.
Eliminating the productions containing the nongenerating symbols we get
S a
A b
Now we see A is not reachable fromS, so we can eliminate the second production to get
S a This is final Simplified CFG
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 23
Eliminating -productions from a CFG
- Consider a CFG given as S aA ; A a | . Note that this CFG will generate a language
of strings that begin with a. The empty string cannot be part of the language
generated by this CFG. Hence if L is the language generated by the above given CFG,
then we see that L does not have although there is a production rule A . Such
productions can be removed from the original CFG without changing the Language
generated.
- A nonterminal A in a grammar is nullableif A
*
.
- The nullable nonterminals can be determined iteratively.
- We can eliminate all -productions in a grammar as follows:
o Eliminate all productions with bodies.
o Suppose A X
1
X
2
... X
k
is a production and mof the kX
i
's are nullable. Then add
the 2
m
versions of this production where the nullable X
i
's are present or absent.
(But if all symbols are nullable, do not add an -production.)
- Let us eliminate the -productions from the grammar G
S AB
A aAA |
B bBB |
S, A and B are nullable.
For the production S AB we add the productions S A | B
For the production A aAA we add the productions A aA | a
For the production B bBB we add the productions B bB | b
The resulting grammar H with no -productions is
S AB | A | B
A aAA | aA | a
B bBB | bB | b
Eliminating Unit Productions from a CFG
- A unit production is one of the formA B where both A and B are nonterminals.
- Let us assume we are given a grammar G with no -productions.
- From G we can create an equivalent grammar H with no unit productions as follows.
Removal of Unit Productions
If we have a production A B (which is a unit production) and B is not a unit production
then add a production A .
- Consider one example which is the standard grammar G for arithmetic expressions:
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 24
E E + T | T
T T * F | F
F ( E ) | a
The unit productions in this CFG are
E T
T F
To remove these unit productions we can replace T on the right side of production E T
with E T * F | F (because T T * F | F)
But now we have added one more unit production E F which can be written as E ( E )
| a because F ( E ) | a.
Similar process can be done on the unit production T F
The equivalent grammar H with no unit productions is:
E E + T | T * F | ( E ) | a
T T * F | ( E ) | a
F ( E ) | a
d) Decision properties of regular languages
Decision Properties of Regular languages
Given regular languages, specified in any one of the four methods (regular expression, DFA,
NFA , NFA with E-moves) , can we develop algorithms that
answer the following questions:
1. Is the language empty?
2. Is the language finite?
3. Is a given string in the language?
The term Decision property means what we can conclude from regular expression OR DFA. In
other words If regular expression OR DFA is given what can we know about the language
accepted
For example if R is the regular expression. We want to find out
i) Membership : Is the string w in Language recognized by regular expression R.
ii) Emptiness : Is the language recognized by regular expression empty.
iii) Finiteness : Is the language recognized by regular expression finite.
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 25
e) Rice theorem
Rice's theorem states any nontrivial property about the language recognized by a Turing machine
is undecidable.
An example of a property of Turing-recognizable languages could be, say, the property of being
a regular language.
The following problems are all undecidable. Given Turing machine M,
1. does M accept the empty string?
2. does M accept no inputs at all?
3. does M accept all inputs?
4. is L(M) regular ? Context-free ? Turing-decidable?
Dec 2012
Q1 (a) What is finite Automata? Give the finite automata M for accepting
(a, b)* (b aaa)
Finite Automata M is defined as a machine with finite number of states. Such a machine
reads input string and recognizes whether the string is ACCEPTED or REJECTED by the language or
not.
Eg : We can design finite automata which will accept string over {0, 1} only if the strings
begin with 0 and end with 1.
In general finite automata M is defined as 5 tuple.
M = { Q E, o, q
0
, F }
where Q = finite set of states
E = finite set of i/p symbols
o = transition function
o = Q x E Q
q
0
= initial state
F = set of final states.
FA can be any of following types
(a) DFA (Deterministic finite automata)
(b) NFA (Non deterministic finite automata)
(c) NFA with moves
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org
NFA for the language (a, b)* (baaa) is
Q1 (b) Explain Chomsky Heivarchy with language used forms of productions in grammer
& accepting devices.
The Chomsky hierarchy is a way of classifying formal grammars into four types
The Chomsky hierarchy consists of the following levels:
Type-0 grammars (unrestricted grammars
exactly all languages that can be recognized by a
known as the recursively enumerable languages
recursive languages which can be
Type-1 grammars (context-sensitive grammars
These grammars have rules of the form
and strings of terminals and nonterminals. The strings
must be nonempty. The rule
any rule. The languages described by these grammars are exactly all languages that can be
recognized by a linear bounded automaton
is bounded by a constant times the length of the input.)
Type-2 grammars (context-free grammars
defined by rules of the form
nonterminals. These languages are exactly all languages
deterministic pushdown automaton
the syntax of most programming languages
Type-3 grammars (regular grammars
restricts its rules to a single nonterminal on the left
consisting of a single terminal, possibly followed (or preceded, but not both in the same
grammar) by a single nonterminal. The rule
appear on the right side of any rule. These languages are exactly all languages that can be
decided by a finite state automaton
obtained by regular expressions
patterns and the lexical structure of programming languages.
b
q
0
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
NFA for the language (a, b)* (baaa) is
xplain Chomsky Heivarchy with language used forms of productions in grammer
is a way of classifying formal grammars into four types
The Chomsky hierarchy consists of the following levels:
unrestricted grammars) include all formal grammars. They generate
exactly all languages that can be recognized by a Turing machine. These languages are also
recursively enumerable languages. Note that this is different fr
which can be decidedby an always-halting Turing machine
sensitive grammars) generate the context-sensitive languages
These grammars have rules of the form with a nonterminal and
strings of terminals and nonterminals. The strings and may be empty, but
must be nonempty. The rule is allowed if does not appear on the right side of
any rule. The languages described by these grammars are exactly all languages that can be
linear bounded automaton (a nondeterministic Turing machine whose tape
is bounded by a constant times the length of the input.)
free grammars) generate the context-free languages
with a nonterminal and a string of terminals and
nonterminals. These languages are exactly all languages that can be recognized by a non
pushdown automaton. Context-free languages are the theoretical basis for
programming languages.
regular grammars) generate the regular languages. Such a grammar
restricts its rules to a single nonterminal on the left-hand side and a right-hand side
consisting of a single terminal, possibly followed (or preceded, but not both in the same
by a single nonterminal. The rule is also allowed here if
appear on the right side of any rule. These languages are exactly all languages that can be
finite state automaton. Additionally, this family of formal languages can be
regular expressions. Regular languages are commonly used to define search
patterns and the lexical structure of programming languages.
a
a
a
q
1
q
2
q
3
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 26
xplain Chomsky Heivarchy with language used forms of productions in grammer
) include all formal grammars. They generate
. These languages are also
. Note that this is different from the
uring machine.
sensitive languages.
a nonterminal and ,
may be empty, but
appear on the right side of
any rule. The languages described by these grammars are exactly all languages that can be
(a nondeterministic Turing machine whose tape
free languages. These are
a string of terminals and
that can be recognized by a non-
free languages are the theoretical basis for
. Such a grammar
hand side
consisting of a single terminal, possibly followed (or preceded, but not both in the same
does not
appear on the right side of any rule. These languages are exactly all languages that can be
. Additionally, this family of formal languages can be
define search
q
4
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org
Grammar Languages
Type-0
Recursively
enumerable
Turing machine
Type-1 Context-sensitive
Linear
machine
Type-2 Context-free Non
Type-3 Regular Finite state automaton
Q1 (c) Differential between mealy & moore
Moore Machine
1 It is FSM in which output depends only on
the current state.
2. For a Moore Machine M=(Q,E, o, ,
Where
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
Automaton
Production rules
(constraints)
Turing machine
Linear-bounded non-deterministic Turing
machine
Non-deterministic pushdown automaton
Finite state automaton and
Differential between mealy & moore machines.
Mealy Machine
It is FSM in which output depends only on It is FSM in which output depends on th
current state, and current input
E, o, , q

,I) For a Mealy Machine M=(Q


Where
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 27
Production rules
(constraints)
(no restrictions)
It is FSM in which output depends on the
current state, and current input
For a Mealy Machine M=(Q,E, o, , q

,I)
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 28
Q= finite set of states.
E =Finite set of i/p symbol
o = Transfer function
o: Q x E Q
=output function
: Q I

q
0
= Initial State
I = finite set of output symbols
Q= finite set of states.
E =Finite set of i/p symbol
o = Transfer function
o: Q x E Q
=output function
: Q x E I

q
0
= Initial State
I = finite set of output symbols
3. If the input given to Moore machine has n
symbols, then output of Moore machine has n+1
symbols. Therefore length of output is one more
then length of input
If the input given to mealy machine has n
symbols, then output of mealy machine has n
symbols. Therefore length of output equal to
length of the input.
Q1 (d) Give example & explain ambiguous context free grammer.
An ambiguous grammar is a formal grammar for which there exists a string that can have more than
one leftmost derivation, while an unambiguous grammar is a formal grammar for which every valid
string has a unique leftmost derivation.
The context free grammar
A A + A | A A | a
is ambiguous since there are two leftmost derivations for the string a + a + a:
LeftMost Derivation 1
A -> A + A
a + A
a + A + A
a + a + A
a + a + a which is the required string
LeftMost Derivation 2
A -> A + A
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 29
A + A + A
a + A + A
a + a + A
a + a + a which is the required string
As another example, the grammar is ambiguous since there are two parse trees for the string a +
a a:
Q2 a) Design a finite state machine that adds 2 binary numbers of equal length
We want to construct a finite state machine that will add two numbers.
The input is two binary numbers, (x
n
x
1
x
0
)
2
and (y
n
y
1
y
0
)
2
At each step, we can compute (x
i
+y
i
) starting with (x
0
+y
0
).
If (x
i
+y
i
)=0, we output 0.
If (x
i
+y
i
)=1, we output 1.
If (x
i
+y
i
)=2, we have a problem.
The problem is we need a carry bit.
In fact, our computation needs to know the carry bit at each step (so we compute x
i
+y
i
+c
i
at each step),
and be able to give it to the next step.
We can take care of this by using states to represent the carry bit.
We will use the following states
State S
0
occurs if the carry bit is 0
State S
1
occurs if the carry bit is 1
Since when we begin the computation, there is no carry, we can use S
0
as the start state,
So, how does which state we are in affect the output?
If we are in state S
0
(we have a carry of 0)
If (x
i
+y
i
)=0, we output 0, and stay in state S
0
If (x
i
+y
i
)=1, we output 1, and stay in state S
0
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 30
If (x
i
+y
i
)=2, we output 0, and go to state S
1
If we are in state S
1
(we have a carry of 1)
If (x
i
+y
i
+1)=1, we output 1, and go to state S
0
If (x
i
+y
i
+1)=2, we output 0, and stay in state S
1
If (x
i
+y
i
+1)=3, we output 1, and stay in state S
1
From the previous observations, we can construct the state table and state diagrams
for the binary adder
Next State Output
Input Input
State 00 01 10 11 00 01 10 11
S
0
S
0
S
0
S
0
S
1
0 1 1 0
S
1
S
0
S
1
S
1
S
1
1 0 0 1
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 31
Q2 (b) Give rules for defining languages associated with any regular expression.
Let L
1
= all words beginning with a
Let L
2
= all words ending with a
What is L
1
intersection L
2
?
Q3 (a) Give the statement for pumping lemma for regular langauages.
Q3 (b) Construct NFA with moves for
(i) (00 + 1 )* (10)*
(ii) (( 0 + 1 )* 10 + ( 00 )* ( 11 )* )*
(i) (00 + 1 )* (10)*
c
c
0
0
c
c
c
c
c
c
c c
c
c
c 1 1
0
0

TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)


Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 32
(ii) (( 0 + 1 )* 10 + ( 00 )* ( 11 )* )*
Q5 a) Explain basic complexity classes
P problems are questions that have a yes/no answer and can be easily solved by a computer.
For example, determining whether a number is prime is a relatively easy problem to solve.
Problems with solution times bound by a polynomial of a small degree are called P problems
Most searching and sorting algorithms are P problems
P problems are also called tractable algorithms
For example, Binary search performs in O(lgn) , Quick sorting performs in O(nlogn)
NP problems are questions that have yes/no answers that are easy to verify, but are hard to
solve. And by hard, we mean it would take years, decades or centuries for our computer to
come up with an answer.
c c
c
c
0
c
c c 1
1 c
c
c
c
c
c
c
c 1
0
0
1
c
c
c
c
c
c
c
c
0
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 33
Problems with best known algorithms not bound by a polynomial
Hard, or intractable problems
Traveling salesperson , knapsack problem
None of the problems in this group has been solved by any polynomial time algorithm
For example, the travelling salesman problemis trying to figure out the shortest trip through a
bunch of cities, visiting each city only once.
Let's say we have a question, can we visit these 500 cities in the state and spend less than 3000
miles on the road? If we magically show an itinerary that takes us to all those 500 cities, you
can easily verify whether that itinerary is less than 3000 miles. BUT, trying to come up with that
itinerary in the first place is really hard for computers.
NP-complete problems are special kinds of NP problems. You can take any kind of NP problem
and twist and convert it until it looks like an NP-complete problem.
For example, the knapsack problemis NP. It can ask what's the best way to fill a knapsack if you
had n number of objects and that you can't carry all of them in the bag.
We can convert Knapsack problem into a travelling salesman problem. In fact, any NP problem
can be made into a travelling salesman problem, which makes travelling salesman NP-
complete.
A problem that is NP-complete can be solved in polynomial time if all other NP-complete
problems can also be solved in polynomial time
NP-Hard problems are worst than NP problems. Even if someone suggested you a solution to a
NP-Hard problem, it'd still take forever to verify if they were right.
If an NP-hard problem can be solved in polynomial time then all NP-complete problems can also
be solved in polynomial time
Q 5 b) Explain NP hard and NP complete language
Q 5 c) Using pumping lemma prove that a
n
b
n
is regular or not.
Prove that L = {a
n
b
n
: n >0} is not regular.
5. Let L be regular. Then there exists a DFA which will accept this language. Let P be the
pumping length
6. Choose a string w = a
p
b
p
. Clearly |w| >= p
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 34
7. Decompose w into xyz, but since |xy| <= p, xy must consist entirely of a's. Moreover, y
cannot be empty(ie |y| > 0). Let us assume that y = a.
8. Choose i = 2. This has the effect of adding one more a, without affecting the number of
b's. The resultant string has more a's than b's, hence does not belong to L. Therefore L is
not regular.
Q 6 a) How is a regular expression converted to DFA. Explain all the rules with example.
Conversion of RE into a DFA is accomplished in two steps: first it converts a RE into a non-
deterministic finite automaton (NFA) and then it converts the NFA into a DFA.
A NFA is similar to a DFA but it also permits multiple transitions over the same character and
transitions over . The first type indicates that, when reading the common character associated
with these transitions, we have more than one choice; the NFA succeeds if at least one of these
choices succeeds. The transition doesn't consume any input characters, so you may jump to
another state for free.
Clearly DFAs are a subset of NFAs. But it turns out that DFAs and NFAs have the same
expressive power.
To convert a RE into a NFA there are only 5 rules, one for each type of RE:
The algorithm constructs NFAs with only one final state. For example, the third rule indicates
that, to construct the NFA for the RE AB, we construct the NFAs for A and B which are
represented as two boxes with one start and one final state for each box. Then the NFA for AB is
constructed by connecting the final state of A to the start state of B using an empty transition.
For example, the RE (a|b)c is mapped to the following NFA:
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 35
The next step is to convert a NFA to a DFA (called subset construction). Suppose that you assign
a number to each NFA state. The DFA states generated by subset construction have sets of
numbers, instead of just one number. For example, a DFA state may have been assigned the set
{5,6,8}. This indicates that arriving to the state labeled {5,6,8} in the DFA is the same as
arriving to the state 5, the state 6, or the state 8 in the NFA when parsing the same input.
First we need to handle transitions that lead to other states for free (without consuming any
input). These are the transitions. We define the closure of a NFA node as the set of all the
nodes reachable by this node using only transitions. For example, The closure of node 1 in the
left figure below
is the set {1,2}. The start state of the constructed DFA is labeled by the closure of the NFA start
state. For every DFA state labeled by some set and for every character c in the
language alphabet, you find all the states reachable by s
1
, s
2
, ..., or s
n
using c arrows and you
union together the closures of these nodes. If this set is not the label of any other node in the
DFA constructed so far, you create a new DFA node with this label. For example, node {1,2} in
the DFA above has an arrow to a {3,4,5} for the character a since the NFA node 3 can be
reached by 1 on a and nodes 4 and 5 can be reached by 2. The b arrow for node {1,2} goes to the
error node which is associated with an empty set of NFA nodes.
The following NFA recognizes , even though it wasn't constructed with the 5 RE-
to-NFA rules. It has the following DFA:
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org
Q7 d) Closure properties of CFL
Context-free languages are closed
free languages, the following languages are context
- the union of Land
- the reversal of L is also context free language
- the concatenation of
- the Kleene star of L is also context free language
Context-free languages are not closed under
L is a context-free language and D
their difference are context
Q7 e) Application areas of RE, FA, PDA, CFG, TM
Application of RE
Lexical analysis : RE is used for performing Lexical analysis. Lexical analysis is the
process of tokenizing a sequence of symbols to eventually parse a string. The Java
compiler will separate out each token (variable , constants , keywords and so on).
This is done in the first step of compiling any Java program.
Application areas of FA
Pattern Matching : Finding an occurrence of short string in the long string is called
pattern matching and this is done by using FA. For example finding whether mat
appears in the word mathematics.
Lexical analysis : FA is used for performing
process of tokenizing a sequence of symbols
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
www.gloriousacademy.org (Ph 9920030136 , 25621515)
Q7 d) Closure properties of CFL
closed under the following operations. That is, if L and
free languages, the following languages are context-free as well:
and P is also context free language
is also context free language
of Land P is also context free language
is also context free language
free languages are not closed under complement, intersection, or difference
D is a regular language then both their intersection
are context-free languages.
Q7 e) Application areas of RE, FA, PDA, CFG, TM
RE is used for performing Lexical analysis. Lexical analysis is the
process of tokenizing a sequence of symbols to eventually parse a string. The Java
compiler will separate out each token (variable , constants , keywords and so on).
rst step of compiling any Java program.
Pattern Matching : Finding an occurrence of short string in the long string is called
pattern matching and this is done by using FA. For example finding whether mat
athematics.
Lexical analysis : FA is used for performing Lexical analysis. Lexical analysis is the
process of tokenizing a sequence of symbols to eventually parse a string
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Page 36
and P are context-
difference. However, if
is a regular language then both their intersection and
RE is used for performing Lexical analysis. Lexical analysis is the
process of tokenizing a sequence of symbols to eventually parse a string. The Java
compiler will separate out each token (variable , constants , keywords and so on).
Pattern Matching : Finding an occurrence of short string in the long string is called
pattern matching and this is done by using FA. For example finding whether mat
Lexical analysis is the
to eventually parse a string. The Java
TCS Sem V Computer Paper Solution By Prof Sameer Y Velankar (9324793514)
Glorious Academy www.gloriousacademy.org (Ph 9920030136 , 25621515) Page 37
compiler will separate out each token (variable , constants , keywords and so on).
This is done in the first step of compiling any Java program.
Application areas of PDA
PDA is used for recognizing Context free Language (which is also defined by
Context free Grammar). For example the Language L = {a
n
b
n
| n >= 1} can be
recognized by PDA.
Actually PDA is used in the second phase of compilation which is syntax check.
Example
a) Check whether expression has balanced parenthesis.
b) Check whether number of curly braces open are matching corresponding curly
braces close in a Java program.
Application areas of Turing machine
Turing machine is a hypothetical computer defined by Alan Turing which can be
used for
a) Lexical analysis (which can also be done by RE or FA)
b) Syntax check (which can also be done by PDA)
c) Computing a mathematical expression and writing output on the tape. For
example multiplying 2 unary numbers and storing the result on the tape. This can
be done only by Turing machine and not by FA or PDA.
Hence Turing machine is the most powerful machine (in terms of problem solving
ability) as compared to FA or PDA.

You might also like