Академический Документы
Профессиональный Документы
Культура Документы
UNIT –I
1) What is meant by finite automata?
Finite automaton is a mathematical model of a system with discrete inputs and outputs. The system can be
in any one of the finite number of states. The state of the system summaries the information concerning past
inputs that is needed to determine the behavior of the systems on subsequent inputs. A finite automaton
consists of a finite set of states and set of transitions from state to state that occur on input symbols chosen
from an alphabet ∑.
Head pointer:
The head examines only one square at a time and can move one square either to the left or to the right but
we restrict the movement of the reading head pointer only to the right-side.
Finite control:
The finite control contains the routines that instruct the reading head pointer to move from one state to the
next state by recognizing each symbol or alphabet.
DFA
For each and every state and for each and every input symbol there exist atmost one transition. The
transition mapping for DFA is Q×∑→Q.
NFA
For each and every state and for each and every input symbol there exist more than one transition. The
transition mapping for NFA is Q × (∑ U { }) → .
i. Transition Diagram.
ii. Transition Table.
Transition Diagram:
The transition diagram consists of finite set of states, symbols, initial state and final state. It is a
directed graph which shows the transition from one state to another.
Transition Table:
The transition table is the tabular representation of the transition function “delta (∂)” with the rows
denoting states and columns denoting input symbol.
6) Define a language.
An alphabet is a finite set of symbols. A language is a set of strings of symbols from someone alphabet.
e.g.
If ∑ = {0,1},then ∑* }.
a
Q1
Q0
The “ ” is a character used to indicate the null string (i.e) the string which is used simply for transition
from one state to the other without any input. The NFA with € transition function can be extended to ∂‟ as
∂‟=Q×∑*→
Let „r‟ be the regular expression then there exists a NFA with -transition that accepts L(r)
(i.e.) L(M)=L(r).
Where the regular expression “r” belonging to a language “L” can be accepted by automata with
.
DFA NFA
i. For each and every state and i. For each and every state and for
for each and every input each and every input symbol
symbol there exist atmost one there exist more than one
transition. transition.
ii. The transition mapping for ii. The transition mapping for NFA
DFA is Q×∑→Q. is Q × (∑ U { }) → .
iii. The language accepted by iii. The language accepted by NFA is
DFA is denoted as L(M). denoted by L(M‟).
iv. Epsilon transition is not iv. Epsilon transition is possible.
possible.
There are main operations that are closed under regular expression,
i. Union.
ii. Concatenation.
iii. Kleene Closure.
Union :
Let r1 and r2 be the regular expressions and the union of these two regular expressions are denoted as
r1 U r2 or r1+r2 the general form of representation of union operation is given by,
M==(Q1UQ2 U{q0,f0},∑1U∑2,∂,q0,{f0}).
Concatenation:
Let r1 and r2 be the regular expressions and the union of these two regular expressions are denoted as
r1. r2 or r1r2 the general form of representation of concatenation operation is given by,
M==(Q1UQ2 ,∑1U∑2,∂,q0,{f0})
Kleene Closure :
Let r1 be the regular expressions and the union of these two regular expressions are denoted as r 1* or
the general form of representation of kleene closure is given by,
M==(Q1U{q0,f0},∑,∂,q0,{f0})
Lexical Analysis.
Pattern searching.
An automaton in which the output depends on the states of the states of the machine is called
Moore machine. An automaton in which
the output depends on the state as well as on the input at any instant of time is called a Mealy machine.
22) Construct a DFA with for all the set of strings with {0, 1} that has even number of 0’s and 1’s.
1
q0 1 q1
0 1 0 0
1
q4 q3
1
23)Construct DFA for set of all strings {0,1} with 011 as substring.
0 0 1
q3
q0 q1 q2
1
1 0 1/0
¢ a b a $
FC
26) Construct a NFA with -moves when a regular expression is given: r =01/101?
Taking r =01,
r1=0 r2=1
0 1
q0 q1 q2 q3
r3=r1r2
q0 q1 q2 q3
0 1
Taking r=101,
r7=r4r5r6
1 0 1
q4 q5 q6 q7 q8 q9
Now r=01/101
0 1
q0 q1 q2 q3
q10 q11
1 0 1
q4 q5 q6 q7 q8 q9
a
q0 q2 q3
a b
q1
28) Explain the transition mapping regarding finite automata with -moves?
29) Give the transition mapping for moore and mealy machine?
For moore machine the transition mapping is:
:Q x .
For mealy machine the transition mapping is:
:Q .
a b b
b a
q0 q1 q2
UNIT -II
Let L be a regular set. Then there is a constant n such that if Z is any word in L, and |z|≥n. we may
write Z=uvw in such a way that |uv| ≤ n, |v| ≥ 1and for all L ≥0 then uv iw is in L.
The pumping lemma is a powerful tool providing and proving certain language is regular or not.
It is also useful in the development of algorithms to answer certain question concerning finite
automata, such as whether the language accepted by a given FA is finite or infinite.
3. What is homomorphisms?
A string homomorphism is a function on strings that works by substituting a particular string for
each symbol.
Example: The function h given by h(0) = abb and h(1) = ba is a homomorphism which replaces
each 0 by abb and each 1 by ba. Thus h(1011) = baabbbaba.
7. What is reversal?
The reversal of a string a1a2...anis the string written backwards, that is, a nan-1…a1. We use wR for
the reversal of string w. thus, 0010R is 0100, and ЄR = Є. The reversal of language L, written LR, is the
language consisting of the reversals of all its strings. For instances, if L ={001, 10, 111}, then L R
={100,01,111}.
10. Verify the language Lpal of palindromes of 0’s and 1’s is regular language or not?
To verify this we use pumping lemma. If L pal is a regular language, let n be the associated constant,
and consider the palindrome w =0 n10n. If Lpal is regular, then we can break w into w = xyz, such that y
consist of one or more 0‟s from the first group. Thus, xz, which would also have to be Lpal if Lpal were
regular, would have fewer 0‟s to the left of the lone 1 than there are to the right of the 1. Therefore xz
cannot be a palindrome. So we have now contradicted the assumption that L pal is a regular language.
derivation. It is denoted by . At each step when the rightmost variable is replaced by one of its bodies
L(G)={w in T* | S w}
If a language L is the language of some context-free grammar, then L is said to be a CFL.
32. What are the notation for CFG derivation?
There are a number of conventions in common use that help us remember the role of the symbols we use
when discussing CFG‟s. Here are the conventions we shall use:
a. Lower-case letters like a, b are called terminal symbols.
b. Upper-case letters like A, B are variables.
c. Lower-case letter near the end of the alphabet are string of terminals.
d. Upper-case letters near the end of the alphabet are either terminals or variables.
e. Lower-case Greek letters are strings consisting of terminals and/or variables.
33. The following grammar generates the grammar of the language consisting of all strings of even
length:
S→AS|ε
A→ aa|ab|ba|bb
Give leftmost and rightmost derivations for the following strings:
aabbba
Solution:
Leftmost derivation:
S AS
aaS
aaAS
aabbAS
aabbbaS
aabbba
Rightmost derivation:
SAS
AAS
AAAS
AAA
AAba
Abbba
aabbba
3≤4
|v|≥1
uviw
= 0(00)i0
When i=1
=0(00)10
=0000
When i=2
=0(00)20
=000000
Thus the string 000000 is not present in the set so it is not a regular set.
Thus the string 001011 is not present in the set so it is not a regular set.
=011
When i=2
=0(1)21
=0111
Thus the string 0111 is present in the set so it is a regular set or regular language.
38. What is the language generated by the grammar G=(V,T,P,S) where P={S->aSb,
a. S->ab}?
S==> aSb
==>aaSbb
==>aaabbb
i.e the general form is anbn
Thus the language L(G)={ anbn | n>=1}. The language has strings with equal number of a‟s
and b‟s.
39. What are the three ways to simplify a context free grammar?
a. By removing the useless symbols from the set of productions.
b. By eliminating the empty productions.
c. By eliminating the unit productions.
41. Find the grammar for the language L={ a2nbc, where n>1 }
Let G=( {S,A,B}, {a,b,c}, P, {S} ) where P:
SAbc
AaaA
UNIT – III
δ Set of Transitions.
q0Initial state.
Q * (Σ U e) * Γ Q* Γ*
where Γ is a finite set of stack symbols and Γ* consist of stack symbols with z0.
5. What are the additional features of PDA has when compared with NFA?
In PDA we use push down list called stack which is not used in NFA. Also we use cache memory and
auxiliary memory which is not present in NFA. We have 7 tuples in PDA they are M= {Q, Σ, δ, Γ, q0, z0,
F)
The additional 2 tuples which are present in PDA and not in NFA are Γ and Z 0.
B C
This directed graph can be called as a directed acyclic graph since it has no cycles in it.
STEP 1:
¢ a a b b $
F.C
a
Z0
Transition mapping : δ(q0,a, Z0) = (q1, aZ0)
STEP 2:
¢ a a b b $
F.C
a
a
Z0
Transition mapping : δ(q1,a, a) = (q2, aaZ0)
STEP 3:
¢ a a b b $
F.C
a
a
Z0
Transition mapping: δ(q2,b, a) = (q3, aZ0)
STEP 4:
¢ a a b b $
F.C
a
Z0
23. Consider G whose productions are SaAS |a , ASbA| SS |ba ,Show that S => aabbaa and
construct a derivation tree.
S aAS
aSbAS
aabAS
aabbaS
aabbaa
a A S
S b A a
a b a
24. Explain the shit reduce parser for id1*id2 with actions if EE+E , EE*E, E(E), Eid.
Input string Stack Diagram Action
id1*id2 $ Start
*id2 E Reduce
E
id2 E* Shift
*
E
$ E*id2 Shift
id2
*
E
$ E*E Reduce
E
*
E
$ E Reduce
E
$ E Accept
E
25. Whether id1 – id2 is accepted by the shift reduce parser? Justify.
-id2 E Reduce
E
id2 E- Shift
-
E
$ E-id2 Shift
id2
-
E
$ E-E Reduce
E
-
E
$ E-E Error
E
-
E
26. In a production if A is the start symbol with rank zero then show that the length of the string is
finite.
Consider the production Aa,
The directed acyclic graph for above production can be given as,
By the assumption of Decision algorithm , a non terminal with rank r cannot generate a string of length
greater than 2r ,
Here r = 0,
l ≤ 2r
l ≤ 20
l≤1
28. Consider the grammar with productions S AB, AB, Bb. whether the length of the string
generated by the grammar is finite or infinite. Justify.
S AB
AB
Bb
A B
The graph does not contain any cycles. Hence the length of the string produced by the grammar is
finite. This can also be proved by the assumption of Decision algorithm,
A non terminal with rank r cannot generate a string of length greater than 2 r ,
l ≤ 2r
l ≤ 22
l ≤ 4 which is finte.
The language accepted by NFA is the The language accepted by PDA is context
regular language. free language.
For some state q in F and any state string α. That is, starting in the initial ID with w waiting on the
input, P consumes w from the input and enters an accepting state. The contents of the stack at that time is
irrelevant.
33. Define acceptance by empty stack.
For each PDA P= {Q, Σ, δ, Γ, q0, z0, F}, we also define
For any state q. That is, N(P) is the set of input w that P can consume and at the same tme
empty its stack.
34. Is it true that the language accepted by a PDA by empty stack and final states are different
languages.
No, because the languages accepted by PDA‟s by final state are exactly the language accepted by
PDA‟s empty stack.
NPDA DPDA
NPDA is the standard PDA used in The standard PDA in practical situation is
automata theory. DPDA.
Every PDA is NPDA unless otherwise The PDA is deterministic in the sense, that
specified. at most one move is possible from any ID.
UNIT-IV
1. What is the difference between the Turing machine and the Finite automata?
Finite automata Turing machine
Here the input tape is closed at both the Here the input tape is infinite at one end
ends. either at the left or at right usually at the
right side.
The reading pointer moves only one side. Here the read/write head pointer moves to
right or left or stay at a square after a
read/write.
3. How many tuples are in the Turing machine? What are they?
Formally a Turing machine(TM) is denoted
M = (Q,∑,┌,§,q0,B,F),
Where
* *
Let S and let f be a function f : S -> . Then we say T computes f or f is computable
if for every x S,
* *
(q0, x) (h, f(x)) and for every x that is not in S, T does not halt on x.
v 1 v 2 3 h 4 5 6 v 7 8 9
10 h 11 ... ...
1) Change state
2) Prints a new symbol on each of the cells scanned by its tape heads;
3) Move each of its tape heads, independently, one cell to the left , or right, or keep it stationary.
Initially the input appears on the first tape, and the other tapes are blank.
17. What is the difference between Semi infinite and two way infinite tapes?
In case of semi infinite tape TM only one side In case of two way infinite tape both the sides
of the input tape is infinite. of the input tape is infinite.
The head pointer moves only to the infinite Here the head pointer moves in both sides
side of the input tape. infinitely.
It is also useful when lengths of substrings must be compared , such as in the languages
We extract an extra track on the tape that holds a blank or √. The √ appears when the symbol
below it has been considered by the TM in one of its comparisons.
TM has a tape head that moves both left FA doesn‟t have such a tape head.
and right side
A function f(i1,…ik) computed by a Turing machine is called a partial recursive function. They
are similar to r.e languages as they are computed by TM that may or may not halt on a given input.
The recursive sets include languages accepted by at least one TM that halts on all inputs.
36. When a recursively enumerable language is said to be recursive ? Is it true that the language
accepted by a non-deterministic Turing machine is different from recursively enumerable
language?
A language L is recursively enumerable if there is a TM that accepts L and recursive if here is a
TM that recognizes L. Thus r.e language is Turing acceptable and recursive language is Turing decidable
languages.
UNIT-V
1 1 13 2
5 25 49 32
From the table, it is easy to say that the function q(n) grows at a very fast rate when compared to f(n) or
g(n). Hence Exponential function grows at very faster rate when n value increase and polynomial function
grows at lesser rate when n value increases.
12 Define Horn-satisfiability.
A clause is Horn if it contains at most one positive literal. This clauses are able to express
implication of on variable from a set of other variables.
Example: If the set of all values are true then Y needs to be true .
13 Define NP-hardness.
If the problem as a complete set of solution then it is called NP-hard.
16 Define class NP ?
A language L is in the class NP (Nondeterministic polynomial) if there is a nondeterministic TM
M and a polynomial time complexity T(n) such that L=L(M) and when M is given a input of length n,
there are no sequences of more than T(n) moves of M.
Example: The Travelling salesman problem
A Vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least
one vertex of the set.
(Turing decidable languages). TMs that decide (Turing acceptable languages). TMs that semi-
languages are algorithms. decides languages are not algorithms.
In a multi-tape TM ,one tape acts as an output tape, on which a symbol, once written can never be
changed and whose tape head never moves left. On that output tape , M writes strings over some alphabet
∑ , separated by a marker symbol # , G(M) ( where G(M) is the set w in ∑ * such that w is finally printed
between a pair of #‟s on the output device ).
35. State a single tape TM started on blank tape scans any cell four or more times is decidable?
If the TM never scans any cell four or more times , then every crossing sequence is of length at
most three. There is a finite number of distinct crossing sequence of length 3 or less. Thus either TM stays
within a fixed bounded number of tape cells or some crossing sequence repeats.
36. Does the problem of “ Given a TM M ,does M make more than 50 moves on input B “?
Given a TM M means given enough information to trace the processing of a fixed string for a
certain fixed number of moves. So the given problem is decidable.