FLAT Question Bank
FLAT Question Bank
UNIT 1
Explain Context Free Grammars
Note –
CNF is a pre-processing step used in various algorithms.
For generation of string x of length ‘m’, it requires ‘2m-1’
production or steps in CNF.
(q0 ∈ Q).
q0 is the initial state from where any input is processed
Some properties of NFA’s (see Fig. 2.6 for the illustration) ---
Empty string transitions are not seen NDFA permits empty string
in DFA. transitions.
Constructing an FA from an RE
For each pair of states i and j in F2, there is a transition from state
i to state j on input x if there exists a state k that is reachable
from state i via epsilon transitions in F1, and there is a transition
in F1 from state k to state j on input x.
Set complement
String reversal
Set difference
Homomorphism
Q * Σ to Q.
FLAT
UNIT 2
Explain Context-free grammars (CFG) and Context-free
languages (CFL)
CFLs are used by the compiler in the parsing phase as they define
the syntax of a programming language and are used in many
editors.
There are four important components in a grammatical
description of a language:
Formal definition
Note –
CNF is a pre processing step used in various algorithms.
For generation of string x of length ‘m’, it requires ‘2m-1’
production or steps in CNF.
4. Problem
Convert the following CFG into CNF
S → XY | Xn | p
X → mX | m
Y → Xn | o
Solution
Here, S does not appear on the right side of any production and
there are no unit or null productions in the production rule set.
So, we can skip Step 1 to Step 3.
Step 4
Now after replacing
X in S → XY | Xo | p
with
mX | m
we obtain
S → mXY | mY | mXo | mo | p.
And after replacing
X in Y → Xn | o
with the right side of
X → mX | m
we obtain
Y → mXn | mn | o.
Two new productions O → o and P → p are added to the
production set and then we came to the final GNF as the
following −
S → mXY | mY | mXC | mC | p
X → mX | m
Y → mXD | mD | o
O→o
P→p
Here, parse trees are constructed from bottom up, not top down.
E→E+T|E-T|T
T→T*F|F
F→a|(E)
We write:
xn = xn′ ∈ Σ*
Namely they start with the same non-terminal and end at the
same terminal string and have at least two intermediate steps.
Let’s say D < D′ if the two derivations differ in only one step in
which there are 2 non-terminals, A and B, such that D replaces
the left one before the right one and D′ does the opposite.
Formally:
Union
Example
Let A1 = { xnyn , n > 0}. Corresponding grammar G 1 will have P:
S1 → aAb|ab
Let A2 = { cmdm , m ≥ 0}. Corresponding grammar G 2 will have P:
S2 → cBb| ε
Union of A1 and A2, A = A1 ∪ A2 = { xnyn } ∪ { cmdm }
The corresponding grammar G will have the additional
production S → S1 | S2
Concatenation
If A1 and A2 are context free languages, then A1A2 is also context
free.
Example
Union of the languages A1 and A2, A = A1A2 = { anbncmdm }
The corresponding grammar G will have the additional
production S → S1 S2
Kleene Star
If A is a context free language, then A* is also context free.
Example
Let A = { xnyn , n ≥ 0}. Corresponding grammar G will have P:
S → aAb| ε
Kleene Star L1 = { xnyn }*
The corresponding grammar G1 will have additional productions
S1 → SS1 | ε
Context-free languages are not closed under −
Intersection − If A1 and A2 are context free languages, then
A1 ∩ A2 is not necessarily context free.
Intersection with Regular Language − If A1 is a regular
language and A2 is a context free language, then A1 ∩ A2 is a
context free language.
Complement − If A1 is a context free language, then A1’
may not be context free.
FLAT
UNIT 3
Context-sensitive languages
What Is The Difference Between The Strings And The Words Of
A Language?
As you can see we can make a lot of strings from these letters a
and b.
So we can say that all the words are strings but all the strings
may not be the words of a language. Hence strings are any
combination of letters of an alphabet and the words of a language
are strings made according to some rule.
For example
Σ= { a , b } ( Valid Alphabet)
Σ= { a , b , cd } ( Valid Alphabet)
Σ= { a , b , ac } ( Invalid Alphabet)
5. What Is Algol ?
A->0A | 0 , B->1B | 1
S->0S1=>001
S->0S1=>011
S->0S1=>00S11=>000S111=>0000A111=>00000111
Reverse = w
Example: Σ={a,b},
e.g
reverse (xxx) = xxx
reverse (623) = 326
reverse (140) = 041
C->aB
**
S->a
S-
>Ab
S-
>aBa
A->b A->Є B- B->A are the given set
>b of production.
A->b
B->b
Finally the productions are: S-> a | Ab | b | aBa | aa
A->b
B->b
FLAT
UNIT 4
Turing machines
Differentiate Kleene Star Closure And Plus?
You can use other symbol for alphabet but we are mostly use
sigma symbol.
And a* and a+ are called the regular expressions (RE) for L1 and
L2 respectively.
3. What Is The Concept Of Fa Also Known As Fsm ( Finite
State Machine) ?
In every FA, every state shows transition for all letters of given
alphabet but in any TG it is not necessary to show all transition for
all letters of given alphabet. In TG, we may or may not show all
letter transitions according to requirement. We can also show
transitions on reading any strings in TGs but it is not possible in
FA’s. In GTG Directed edges connecting some pair of states are
labeled with regular expressions . It may be noted that in GTG,
the labels of transition edges are corresponding regular
expressions. In TG we write strings and in GTG we are bound to
write RE. Every FA is also a TG but not every TG is FA.
For example
Let A ={1,3,5,7,9}
and
B = {0,2,4,6,8,10}
then, A U B = { 0,1,2,3,4,5,6,7,8,9,10 }
you can see that A U B contain elements of both sets similar is the
case with FA’s.
In TG, there are letter transitions for the strings. While in GTG,
one can write whole RE as a transition from one state to another
one.
While in NFA there may be more than one transition for a letter
from a state. And finally every FA is an NFA while every NFA may
be an FA or not.
Example: (q1, BG) is in δ(q1, 0 , G) tells that (q1, 011, GGR )|----
( q1, 11,BGGR).
Z the top symbol on the stack enter a state pi and replace Z by γi.
FLAT
UNIT 5
Undecidability
There are two or three big differences between FA’s and TG’s.
a set of states
a finite input alphabet from which input strings can be
constructed
a transition function that describes how the automaton
changes states as it processes an input string
a single designated starting state
a set of accepting states
The only difference lies in the transition function, which can now
target subsets of the states of the automaton rather than a single
next state for each state, input pair.
The string is taken for the testing purposes. You can take any sort
of string and determine its output using machine.