0% found this document useful (0 votes)
23 views

FLAT Question Bank

Uploaded by

SAROJ KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

FLAT Question Bank

Uploaded by

SAROJ KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

FLAT

UNIT 1
 Explain Context Free Grammars

Simplifying Context Free Grammars

A context free grammar (CFG) is in Chomsky Normal Form (CNF) if


all production rules satisfy one of the following conditions:

 A non-terminal generating a terminal (e.g.; X->x)


 A non-terminal generating two non-terminals (e.g.; X->YZ)
 Start symbol generating ε. (e.g.; S->ε)

Consider the following grammars,

G1 = {S->a, S->AZ, A->a, Z->z}

G2 = {S->a, S->aZ, Z->a}

The grammar G1 is in CNF as production rules satisfy the


rules specified for CNF. However, the grammar G2 is not in CNF as
the production rule S->aZ contains terminal followed by non-
terminal which does not satisfy the rules specified for CNF.

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.

2. How to convert CFG to CNF?


Step 1. Remove start from RHS. If start symbol S is at the RHS of
any production in the grammar, create a new production as:S0-
>S where S0 is the new start symbol.

Step 2. Remove null, unit and useless productions. If


CFG comprises of any production rules, remove them.

Step 3. Remove terminals from RHS. For eg; production rule X-


>xY can be decomposed as: X->ZY Z->x

Step 4. Remove RHS with more than two non-terminals. e.g,;


production rule X->XYZ can be decomposed as:
X->PZ
P->XY

3. Explain Regular expressions and languages


A Regular Expression can be recursively defined as follows −
 ε is a Regular Expression indicates the language containing
an empty string. (L (ε) = {ε})
 φ is a Regular Expression denoting an empty language. (L (φ)
= { })
 x is a Regular Expression where L = {x}
 If X is a Regular Expression denoting the
language L(X) and Y is a Regular Expression denoting the
language L(Y), then

language L(X) ∪ L(Y) where L(X+Y) = L(X) ∪ L(Y).


 X + Y is a Regular Expression corresponding to the

 X . Y is a Regular Expression corresponding to the


language L(X) . L(Y) where L(X.Y) = L(X) . L(Y)
 R* is a Regular Expression corresponding to the
language L(R*) where L(R*) = (L(R))*
 If we apply any of the rules several times from 1 to 5, they
are Regular Expressions.
UNIX Operator Extensions

Regular expressions are used frequently in Unix:


 In the command line
 Within text editors
 In the context of pattern matching programs such
as grep and egrep

Additional operators are recognized by unix. These operators are


used for convenience only.
 character classes: '[' <list of chars> ']'
 start of a line: '^'
 end of a line: '$'
 Wildcard matching any character except newline: '.'
 Optional instance: R? = epsilon | R
 one or more instances: R+ == RR*

4. What is Deterministic finite automata (DFA) and


equivalence with regular expressions?
In DFA, for each input symbol, one can determine the state to
which the machine will move. Hence, it is called Deterministic
Automaton. As it has a finite number of states, the machine is
called Deterministic Finite Machine or Deterministic Finite
Automaton.
An automaton can be represented by a 5-tuple (Q, ∑, δ, q0, F),
where −
 Q is a finite set of states.
 ∑ is a finite set of symbols, called the alphabet of the
automaton.
 δ is the transition function.

(q0 ∈ Q).
 q0 is the initial state from where any input is processed

 F is a set of final state/states of Q (F ⊆ Q).


A Review (supplemental)
Recall the example of designing a vending machine selling 20-
dolllar food packs in Figure 1.3.2.What abstract concepts are
involved in the design?  See the definition next.
Figure Recall the example

Advantages and disadvantages

 DFAs were invented to model of a Turing machine, which was


too general to study properties of real world machines.
 DFAs are one of the most practical models of computation,
since there is a trivial linear time, constant-space, online
algorithm there are efficient algorithms to find a DFA recognizing:
 The union/intersection of the languages recognized by two
given DFAs.
 The complement of the language recognized by a given DFA.
 On the other hand, finite state automata are of strictly limited
power in the languages they can recognize; many simple
languages, including any problem that requires more than
constant space to solve, cannot be recognized by a DFA. • The
classical example of a simply described language that no DFA can
recognize is bracket language, i.e., language that consists of
properly paired brackets such as word "(( )( ))".

5. What is Non deterministic finite automata (NFA) and


equivalence with DFA?

In NDFA, for a particular input symbol, the machine can move to


any combination of the states in the machine. In other words, the
exact state to which the machine moves cannot be determined.
Hence, it is called Non-deterministic Automaton. As it has
finite number of states, the machine is called Non-deterministic
Finite Machine or Non-

deterministic Finite Automaton.


Q → Finite non-empty set of states.
∑ → Finite non-empty set of input symbols.
∂ → Transitional Function.
q0 → Beginning state.
F → Final State

 Review of a previous example of DFA


 Original version --- see Fig. (the same as Fig.)

Figure Step 1 For NDFA Example

A nondeterministic finite automaton (NFA) version of the above


DFA --- see Fig. 2.
 More intuitive!
 How to design an NFA will be described later.

Figure Step 1 For NDFA Example

Some properties of NFA’s (see Fig. 2.6 for the illustration) ---

Some transitions may “die,” like ˆ  (q2, 0).

Some transitions have multiple choices, like ˆ  (q0, 0) = q0 and


q2.

Example --- Design an NFA accepting the following language L =


{w | w{0, 1}* and ends in 01}.
6. DFA vs NDFA
The following table lists the differences between DFA and NDFA.
DFA NDFA

The transition from a state is to a The transition from a state can


single particular next state for each be to multiple next states for
input symbol. Hence it is each input symbol. Hence it is
called deterministic. called non-deterministic.

Empty string transitions are not seen NDFA permits empty string
in DFA. transitions.

Backtracking is allowed in DFA In NDFA, backtracking is not


always possible.

Requires more space. Requires less space.

A string is accepted by a DFA, if it A string is accepted by a NDFA,


transits to a final state. if at least one of all possible
transitions ends in a final state.

7. Explain Regular grammars and equivalence


with finite automata

Regular expressions and finite automata have equivalent


expressive power:
 For every regular expression R, there is a corresponding FA
that accepts the set of strings generated by R.
 For every FA A there is a corresponding regular expression that
generates the set of strings accepted by A.

The proof is in two parts:


 an algorithm that, given a regular expression R, produces an FA
A such that L(A) == L(R).
 an algorithm that, given an FA A, produces a regular expression
R such that L(R) == L(A).

Our construction of FA from regular expressions will allow


"epsilon transitions" (a transition from one state to another with
epsilon as the label). Such a transition is always possible, since
epsilon (or the empty string) can be said to exist between any two
input symbols. We can show that such epsilon transitions are a
notational convenience; for every FA with epsilon transitions there
is a corresponding FA without them.

Constructing an FA from an RE

We begin by showing how to construct an FA for the operands in a


regular expression.
 If the operand is a character c, then our FA has two states, s0
(the start state) and sF (the final, accepting state), and a
transition from s0 to sF with label c.
 If the operand is epsilon, then our FA has two states, s0 (the
start state) and sF (the final, accepting state), and an epsilon
transition from s0 to sF.
 If the operand is null, then our FA has two states, s0 (the start
state) and sF (the final, accepting state), and no transitions.

Given FA for R1 and R2, we now show how to build an FA for


R1R2, R1|R2, and R1*. Let A (with start state a0 and final state
aF) be the machine accepting L(R1) and B (with start state b0 and
final state bF) be the machine accepting L(R2).
 The machine C accepting L(R1R2) includes A and B, with start
state a0, final state bF, and an epsilon transition from aF to b0.
 The machine C accepting L(R1|R2) includes A and B, with a new
start state c0, a new final state cF, and epsilon transitions from c0
to a0 and b0, and from aF and bF to cF.
 The machine C accepting L(R1*) includes A, with a new start
state c0, a new final state cF, and epsilon transitions from c0 to
a0 and cF, and from aF to a0, and from aF to cF.

Eliminating Epsilon Transitions

If epsilon transitions can be eliminated from an FA, then


construction of an FA from a regular expression can be
completed.

Epsilon transitions offers a choice: It allows us to stay in a


state or move to a new state, regardless of the input symbol.

If starting in state s1, state s2 can be reached via a series of


epsilon transitions followed by a transition on input symbol
x, replacement of the epsilon transitions with a single transition
from s1 to s2 on symbol x.

Algorithm for Eliminating Epsilon Transitions

A finite automaton F2 can be build with no epsilon transitions


from a finite automaton F1 as follows:
 The states of F2 are all the states of F1 that have an entering
transition labeled by some symbol other than epsilon, plus the
start state of F1, which is also the start state of F2.
 For each state in F1, determine which other states are
reachable via epsilon transitions only. If a state of F1 can reach a
final state in F1 via epsilon transitions, then the corresponding
state is a final state in F2.

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.

8. Write some Properties of regular languages

Regular languages are closed under a wide variety of operations.

Union and intersection

Pick DFAs recognizing the two languages and use the


cross-product construction to build a DFA recognizing
their union or intersection. See Sipser Theorem 1.25.
Also see Sipser 1.45 for another way to do union.

Set complement

Pick a DFA recognizing the language, then swap the


accept/non-accept markings on its states.

String reversal

Pick an NFA recognizing the language. Create a new


final state, with epsilon transitions to it from all the old
final states. Then swap the final and start states and
reverse all the transition arrows.

Set difference

Re-write set difference using a combination of


intersection and set complement

Concatenation and Star

Pick an NFA recognizing the language and modify it as


described in Sipser Theorems 1.47 and 1.49

Homomorphism

A homomorphism is a function from strings to strings.


What makes it a homomorphism is that its output on a
multi-character string is just the concatenation of its
outputs on each individual character in the string. Or,
equivalently, h(xy) = h(x)h(y) for any strings x and y. If
S is a set of strings, then h(S) is {w : w = h(x) for some
x in S}.

To show that regular languages are closed under


homomorphism, choose an arbitrary regular language L
and a homomorphism h. It can be represented using a
regular expression R. But then h(R) is a regular
expression representing h(L). So h(L) must also be
regular.

Notice that regular languages are not closed under the


subset/superset relation. For example, 0*1* is regular, but its
subset {On1n : n >= 0} is not regular, but its subset {01, 0011,
000111} is regular again.

9. What is Pumping lemma for regular languages,


minimization of finite automata?

Lemma: The language = is not context free.

Proof (By contradiction)


Assuming that this language is context-free; hence it will have a
context-free grammar.
Let be the constant of the Pumping Lemma.
Considering the string , where is length greater than .
By the Pumping Lemma this is represented as , such that

all are also in , which is not possible, as:

either or cannot contain many letters from


; else they are in the wrong order .

if or consists of a's, b's or c's, then cannot maintain


the balance amongst the three letters.

Lemma: The language = is not context


free.

Proof (By contradiction)


Assuming that this language is context-free; hence it will have a
context-free grammar.

Let be the constant of the Pumping Lemma.


Considering the string , which is > .
By the Pumping Lemma this must be represented as , such

that all are also in .

-As mentioned previously neither nor may contain a mixture


of symbols.

-Suppose consists of a's.


Then there is no way cannot have b's and c's. It generate
enough letters to keep them more than that of the a's (it can do it
for one or the other of them, not both).
Similarly cannot consist of just a's.
-So suppose then that or contains only b's or only c's.

Consider the string which must be in . Since we have


dropped both and , we must have at least one b' or one c' less
than we had in , which was . Consequently, this
string no longer has enough of either b's or c's to be a member
of .

10. Define: (i) Finite Automaton(FA) (ii)Transition


diagram

FA consists of a finite set of states and a set of transitions from


state to state that occur on input symbols chosen from an
alphabet ∑. Finite Automaton is denoted by a

5- tuple(Q,∑,δ,q0,F), where Q is the finite set of states , ∑ is a


finite input alphabet, q0 in

Q is the initial state, F is the set of final states and δ is the


transition mapping function

Q * Σ to Q.

Transition diagram is a directed graph in which the vertices of the


graph correspond to the states of FA. If there is a transition from
state q to state p on input a, then there is an arc labeled ‘ a ‘ from
q to p in the transition diagram.

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:

 There is a set of symbols that form the strings of the language


being defined. They are called terminal symbols, represented by
Vt.
 There is a finite set of variables, called non-terminals. These
are represented by Vn.
 One of the variable represents the language being defined; it is
called the start symbol. It is represent by S.
 There are finite set of rules called productions that represent
the recursive definition of a language. Each production consists
of:

1. A variable that is being defined by the production. This variable


is often called the head of the production.
2. The production symbol ->.
3. A string of zero or more terminals and variable.

Formal definition

A context-free grammar (CFG) is a 4-tuple G=(V n, Vt, S, P), where


Vn and Vt are disjoint finite sets, S is an element of V n, and P is a
finite set of formulas of the form A -> α, where
A ϵ Vn and α ϵ (Vn U Vt)*.

2. What is Chomsky normal forms?

A context free grammar (CFG) is in Chomsky Normal Form (CNF) if


all production rules satisfy one of the following conditions:

 A non-terminal generating a terminal (e.g.; X->x)


 A non-terminal generating two non-terminals (e.g.; X->YZ)
 Start symbol generating ε. (e.g.; S->ε)

Consider the following grammars,

G1 = {S->a, S->AZ, A->a, Z->z}

G2 = {S->a, S->aZ, Z->a}


The grammar G1 is in CNF as production rules satisfy the
rules specified for CNF. However, the grammar G2 is not in CNF as
the production rule S->aZ contains terminal followed by non-
terminal which does not satisfy the rules specified for CNF.

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.

3. What is Greibach normal forms?


A CFG is in Greibach Normal Form if the Productions are in the
following forms −
A→b
A → bD1…Dn
S→ε
where A, D1,....,Dn are non-terminals and b is a terminal.

Algorithm to Convert a CFG into Greibach Normal Form


Step 1 − If the start symbol S occurs on some right side, create
a new start symbol S’ and a new production S’ → S.
Step 2 − Remove Null productions. (Using the Null production
removal algorithm discussed earlier)
Step 3 − Remove unit productions. (Using the Unit production
removal algorithm discussed earlier)
Step 4 − Remove all direct and indirect left-recursion.
Step 5 − Do proper substitutions of productions to convert it into
the proper form of GNF.

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

5. Explain Parse trees


Figure Parse trees

A parse tree is an entity which represents the structure of the

features to define are the root ∈ V and yield ∈ Σ* of each tree.


derivation of a terminal string from some non-terminal. Key

 For each σ ∈ Σ, there is a tree with root σ and no children; its


yield is σ
 For each rule A → ε, there is a tree with root A and one child ε;
its yield is ε
 If t1, t2, ..., tn are parse trees with roots r1, r2, ..., rn and
respective yields y1, y2, ..., yn, and A → r1r2...rn is a production,
then there is a parse tree with root A whose children
are t1, t2, ..., tn. Its root is A and its yield is the concatenation of
yields: y1y2...yn

Here, parse trees are constructed from bottom up, not top down.

The actual construction of "adding children" should be made more


precise, but we intuitively know what's going on.

As an example, here are all the parse (sub) trees used to


build the parse tree for the arithmetic expression 4 + 2 * 3 using
the expression grammar

E→E+T|E-T|T

T→T*F|F

F→a|(E)

where a represents an operand of some type, be it a number


or variable. The trees are grouped by height.
Figure Example of Parse trees

6. Explain Parse Trees and Derivations

A derivation is a sequence of strings in V* which starts with a non-


terminal in V-Σ and ends with a string in Σ*.

Let's consider the sample grammar


E → E+E | a

We write:

E ⇒ E+E ⇒ E+E+E ⇒a+E+E⇒a+a+E⇒a+a+a

but this is incomplete, because it doesn't tell us where the


replacement rules are applied.

We actually need "marked" strings which indicate which non-


terminal is replaced in all but the first and last step:

E ⇒ Ě+E ⇒ Ě+E+E ⇒a+Ě+E ⇒a+a+Ě ⇒a+a+a

In this case, the marking is only necessary in the second step;


however it is crucial, because we want to distinguish between this
derivation and the following one:

E ⇒ E+Ě ⇒ Ě+E+E ⇒a+Ě+E ⇒a+a+Ě ⇒a+a+a

We want to characterize two derivations as "coming from the


same parse tree."

The first step is to define the relation among derivations as being


"more left-oriented at one step". Assume we have two equal
length derivations of length n > 2:

D: x1⇒ x2⇒ ... ⇒xn

D′: x1′ ⇒ x2′ ⇒ ... ⇒xn′

Where x1 = x1′ is a non-terminal and

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:

D < D′ if there exists k, 1 < k < n such that

xi = xi′ for all i ≠ k (equal strings, same marked position)

xk-1 = uǍvBw, for u, v, w ∈ V*

xk-1′ = uAvB̌w, for u, v, w ∈ V*

xk =uyvB̌w, for production A → y

xk′ = uǍvzw, for production B → z

xk+1 = xk+1′ = uyvzw (marking not shown)

Two derivations are said to be similar if they belong to the


reflexive, symmetric, transitive closure of <.

7. Explain Ambiguity in CFG


Suppose we have a context free grammar G with production
rules: S->aSb|bSa|SS|ɛ

Left most derivation (LMD) and Derivation Tree:


Leftmost derivation of a string from staring symbol S is done by
replacing leftmost non-terminal symbol by RHS of corresponding
production rule.
For example: The leftmost derivation of string abab from
grammar G above is done as:

S =>aSb =>abSab =>abab


The symbols in bold are replaced using production rules.

Derivation tree: It explains how string is derived using


production rules from S and is shown in Figure.

Figure Derivation tree

Right most derivation (RMD):


It is done by replacing rightmost non-terminal symbol S by
RHS of corresponding production rule.
For Example: The rightmost derivation of string abab from
grammar G above is done as:

S => SS =>SaSb =>Sab =>aSbab =>abab


The symbols in bold are replaced using production rules.
The derivation tree for abab using rightmost derivation is shown
in Figure.

Figure Right most derivation

A derivation can be either LMD or RMD or both or none. For


Example:

S =>aSb =>abSab =>abab is LMD as well as RMD


butS => SS =>SaSb =>Sab =>aSbab =>abab is RMD but not
LMD.

Ambiguous Context Free Grammar:


 A context free grammar is called ambiguous if there exists
more than one LMD or RMD for a string which is generated by
grammar.
 There will also be more than one derivation tree for a string in
ambiguous grammar.
 The grammar described above is ambiguous because there are
two derivation trees.
 There can be more than one RMD for string abab which are:

S => SS =>SaSb =>Sab =>aSbab =>abab

S =>aSb =>abSab =>abab

8. Explain Pumping lemma for context-free languages

Lemma: The language = is not context free.

Proof (By contradiction)


Assuming that this language is context-free; hence it will have a
context-free grammar.
Let be the constant of the Pumping Lemma.
Considering the string , where is length greater than .
By the Pumping Lemma this is represented as , such that

all are also in , which is not possible, as:

either or cannot contain many letters from


; else they are in the wrong order .

if or consists of a's, b's or c's, then cannot maintain


the balance amongst the three letters.
Lemma: The language = is not context
free.

Proof (By contradiction)


Assuming that this language is context-free; hence it will have a
context-free grammar.

Let be the constant of the Pumping Lemma.


Considering the string , which is > .
By the Pumping Lemma this must be represented as , such

that all are also in .

-As mentioned previously neither nor may contain a mixture


of symbols.

-Suppose consists of a's.


Then there is no way cannot have b's and c's. It generate
enough letters to keep them more than that of the a's (it can do it
for one or the other of them, not both).
Similarly cannot consist of just a's.

-So suppose then that or contains only b's or only c's.

Consider the string which must be in . Since we have


dropped both and , we must have at least one b' or one c' less
than we had in , which was . Consequently, this
string no longer has enough of either b's or c's to be a member
of .

9. Brief Deterministic pushdown automata


 Machine transitions are based on the current state and input
symbol, and also the current topmost symbol of the stack.
 Symbols lower in the stack are not visible and have no
immediate effect. Machine actions include pushing, popping, or
replacing the stack top.
 A deterministic pushdown automaton has at most one legal
transition for the same combination of input symbol, state, and
top stack symbol.
 This is where it differs from the nondeterministic pushdown
automaton.

10. Write Closure properties of CFLs

They are closed under −


 Union
 Concatenation
 Kleene Star operation

Union

Let A1 and A2 be two context free languages. Then A1 ∪ A2 is also


context free.

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?

A string is any combination of the letters of an


alphabet whereas the words of a language are the strings that are
always made according to certain rules used to define that
language.For example if we take

Alphabet Σ = { a , b } Here a , b are the letters of this alphabet.

As you can see we can make a lot of strings from these letters a
and b.

For example a,b,aa,ab,ba,bb,aaa,aab,aba,baa,……………………


and so on.

But when we define a language over this alphabet having no a’s


and only odd number ofb’s. Then the words of this language
would have only those strings that have only odd number of b’s
and no a’s.some example words of our defined language are b ,
bbb , bbbbb , bbbbbbb ,……………………………..and so on.

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.

2. What Is The Difference Between An Alphabet And An


Element Of A Set. Whether Alphabet Is An Element Of A
Set Or It Is A Set Itself?

An Alphabet is a set in itself. The elements of an Alphabet are


called letters.

For example

Binary Alphabet Σ = {0,1}

Here 0,1 are the letters of binary alphabet.

Binary Alphabet is very important because it the Alphabet used


by the computer.

Set of Natural Numbers


N={1,2,3,4,5,…………………………………..}

Here 1,2,3……………………………………. are the elements of set of


Natural Numbers.

3. What Is Null String (Λ) ?

The string with zero occurrences of symbols (letters) from ∑.

It is denoted by (Small Greek letter Lambda) λ or (Capital Greek


letter Lambda) Λ, is called an empty string or null string.

The capital lambda will mostly be used to denote the empty


string, in further discussion.

4. What Is The Concept Of Valid And Invalid Alphabets ?

While defining an alphabet of letters consisting of more than one


symbols, no letter should be started with any other the letter of
the same alphabet i.e. one letter should not be the prefix of
another. However, a letter may be ended in the letter of same
alphabet i.e. one letter may be the suffix of another.

Σ= { a , b } ( Valid Alphabet)
Σ= { a , b , cd } ( Valid Alphabet)
Σ= { a , b , ac } ( Invalid Alphabet)

5. What Is Algol ?

ALGOL (ALGOrithmic Language) is one of several high level


languages designed specifically for programming scientific
computations. It started out in the late 1950’s, first formalized in
a report titled ALGOL 58, and then progressed through reports
ALGOL 60, and ALGOL 68. It was designed by an international
committee to be a universal language. Their original conference,
which took place in Zurich, was one of the first formal attempts to
address the issue of software portability. ALGOL’s machine
independence permitted the designers to be more creative, but it
made implementation much more difficult. Although ALGOL never
reached the level of commercial popularity of FORTRAN and
COBOL, it is considered the most important language of its era in
terms of its influence on later language development.

ALGOL’s lexical and syntactic structures became so popular that


virtually all languages designed since have been referred to as
“ALGOL – like”; that is they have been hierarchical in structure
with nesting of both environments and control structures.

6. What Is Non-determinism And Determinism And What Is


The Difference Between Them ?

Determinism means that our computational model (machine)


knows what to do for every possible inputs. Non determinism our
machine may or may not know what it has to do on all possible
inputs.

As you can conclude from above definition that Non-Deterministic


machine can not be implemented ( used ) on computer unless it is
converted in Deterministic machine.

7. Find the language generated by :S->0S1 | 0A | 0 |1B


|1

A->0A | 0 , B->1B | 1

The minimum string is S-> 0 | 1

S->0S1=>001

S->0S1=>011

S->0S1=>00S11=>000S111=>0000A111=>00000111

Thus L={ 0n 1 m | m not equal to n, and n,m >=1}

8. What Is The Difference Between Palindrome And Reverse


Function?

It is to be denoted that the words of PALINDROME are called


palindromes.

Reverse = w

Example: Σ={a,b},

PALINDROME={Λ , a, b, aa, bb, aaa, aba, bab, bbb, …}

If a is a word in some language L, then reverse (a) is the same


string of letters spelled backwards, called the reverse of a.

e.g
reverse (xxx) = xxx
reverse (623) = 326
reverse (140) = 041

9. Find CFG with no useless symbols equivalent to :


S→AB | CA , B→BC | AB, A→a , C→aB | b.

S-> AB S->CA B->BC B->AB A->a

C->aB

C->b are the given productions.

**

A symbol X is useful if S => αXβ => w

The variable B cannot generate terminals as B->BC and B->AB.


Hence B is useless symbol and remove B from all productions.

Hence useful productions are: S->CA , A->a , C->b

10. Construct CFG without Є production from : S →a | Ab |


aBa , A →b | Є , B →b | A.

S->a
S-
>Ab
S-
>aBa
A->b A->Є B- B->A are the given set
>b of production.

A->Є is the only empty production. Remove the empty production

S-> Ab , Put A-> Є and hence S-> b.

If B-> A and A->Є then B ->Є Hence S->aBa becomes S->aa .


Thus S-> a | Ab | b | aBa | aa

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?

Given Σ, then the Kleene Star Closure of the alphabet Σ, denoted


by Σ*, is the collection of all strings defined over Σ, including Λ.

Plus Operation is same as Kleene Star Closure except that it does


not generate Λ (null string), automatically.

Given Σ, then the Kleene Star Closure of the alphabet Σ, denoted


by Σ*, is the collection of all strings defined over Σ, including Λ.

Plus Operation is same as Kleene Star Closure except that it does


not generate Λ (null string), automatically.

You can use other symbol for alphabet but we are mostly use
sigma symbol.

2. Define Regular Expression?

Regular Expression is the generalized form of any regular


language through which you can construct any string related to
that language.

Take an example from your handouts

L1 = {Λ, a, aa, aaa, …} and L2 = {a, aa, aaa, aaaa, …} can


simply be expressed by a* and a+, respectively.

so a* and a+ are the generalized form of Languages L1, L2.

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) ?

FA (Finite Automaton) is a finite state machine that recognizes a


regular language. In computer science, a finite-state machine
(FSM) or finite-state automaton (FSA) is an abstract machine that
has only a finite, constant amount of memory. The internal states
of the machine carry no further structure. This kind of model is
very widely used in the study of computation and languages.

4. What Is The Difference Between Fa , Tg , Gtg. ?

In every FA, we mark transitions with single letter of the given


alphabet but in TG transitions can be marked with letters or
strings (combination of letters).

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.

5. What Is The Difference Between Fa’s And Tg’s .why We


Need Tg’s When We Have Fa’s?

The Transition Graphs (TG) differ from FA in the following areas

 TG’s are generalizations of FA’s.


 TG’s can change state without an input ( Null transition).
 Can read more than one letter (words of the language they are
accepting) along the transition edges at a time.
 Can have a regular expression as a edge label.
 Can have more then one start state.

We have been given more freedom in TG’s. But this freedom is on


the cost of more memory and processing power it means that if
we implement TG’s on computer using some programming
language it will need more memory and processing power of
computer than used in the implementation of FA’s.
6. What Is The Concept Of The Union Of Fa’s ?

When we take Union of two FA’s it means that resultant FA’s


should accept all the words that were accepted by the two FA’s
individually. It is like taking union of two sets, the resultant set
contain members of both sets.

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.

7. What Is The Difference Between Is Tg And Gtg ?

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.

8. What Is Difference Between Fa’s And Nfa’s. Are They


Opposite To Each Other ?

FA stands for finite automata while NFA stands for non-


deterministic finite automata, In FA there must be a transition for
each letter of the alphabet from each state. So in FA number of
transitions must be equal to (number of states * number of letter
in alphabet).

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.

9. Define Instantaneous description(ID) in PDA.

ID describe the configuration of a PDA at a given instant.ID is a


triple such as (q, w ,γ ) , where q is a state , w is a string of input
symbols and γ is a string of stack

symbols. If M =( Q, Σ ,Ґ ,δ ,q0 ,Z0 ,F ) is a PDA we say that

(q,aw,Zα) |-----( p, w, βα) if δ(q,a,Z) contains (p, β ).


M

‘a’ may be Є or an input symbol.

Example: (q1, BG) is in δ(q1, 0 , G) tells that (q1, 011, GGR )|----
( q1, 11,BGGR).

10. Specify the two types of moves in PDA.

The move dependent on the input symbol(a) scanned is:

δ(q,a,Z) = { ( p1, γ1 ), ( p2,γ2 ),……..( pm,γm ) }

where q qnd p are states , a is in Σ ,Z is a stack symbol and γi is in


Ґ*. PDA is in state q , with input symbol a and Z the top symbol on
state enter state pi Replace symbol Z by string γi.

The move independent on input symbol is (Є-move):

δ(q,Є,Z)= { ( p1,γ1 ), ( p2,γ2 ),…………( pm,γm ) }.

Is that PDA is in state q , independent of input symbol being


scanned and with

Z the top symbol on the stack enter a state pi and replace Z by γi.

FLAT

UNIT 5

Undecidability

 How To Create A Re Of A Particular Language?

Regular expression is used to express the infinite or finite


language, these RE are made in such a way that these can
generate the strings of that unique language also for the cross
check that the defined RE is of a specified language that RE
should accept all the string of that language and all language
strings should be accepted by that RE.

2. How Diagrams Of Fa’s Are Created ?


It depends upon the question how many states involve in a FA.
There is not any formal procedure to design FA for a language.
This ability just improves with time and practice.

Every FA is also a TG but not every TG is FA. In every FA, every


state shows transition of all letters of given alphabet but in any
TG it is not must. In TG, we may or may not show all letters
transition according to requirement. We can also show transitions
on reading any strings in TGs but it is not possible in FAs.

3. What Is The Difference Between Fa’s ,and Tg’s ?

There are two or three big differences between FA’s and TG’s.

In FA there can be maximum one initial or starting state while in


TG there may be more than one initial state.

In FA there can be transition for letters only while in TG transitions


from a state to another one can be for strings.

In FA there must be transition from each state for each letter


(deterministic) while in TG there may be no transition for specific
letter from a state and there may be more than one path for a
string or letter from a state.

4. What Is The Exact Definition Of Fa ?

Definition: A Finite automaton (FA), is a collection of the


followings

 Finite number of states, having one initial and some (maybe


none) final states.
 Finite set of input letters (Ó) from which input strings are
formed.
 Finite set of transitions i.e. for each state and for each input
letter there is a transition showing how to move from one state to
another.

5. What Is The Concept Of Nondeterministic Finite


Automaton (nfa) ?

Nondeterminism plays a key role in the theory of computing. A


nondeterministic finite state automaton is one in which the
current state of the machine and the current input do not
uniquely determine the next state. This just means that a number
of subsequent states (zero or more) are possible next states of
the automaton at every step of a computation. Of course,
nondeterminism is not realistic, because in real life, computers
must be deterministic. Still, we can simulate nondeterminism with
deterministic programs. Furthermore, as a mathematical tool for
understanding computability, nondeterminism is invaluable.

As with deterministic finite state automata, a nondeterministic


finite state automaton has five components.

 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.

6. If A Language Can Be Expressed In The Form Of Fa Than


Why It Is Needed To Use Nfa ?

NFA stands for non-deterministic FA and this sort of structure has


relaxation compared with FA. So it is rather more easy to
represent a language using NFA.

We have methods to convert NFA into FA’s so sometimes it is


easier to build NFA of a given language and than convert its NFA
into FA using these methods rather than directly building an FA
for a language which may be very difficult.

7. How To Made Nfa Corresponding To The Closure Of An Fa


?

While generating NFA corresponding to closure of an FA one


should take care of the null string. Simple way to accept null
string is declare initial state, final as well. But in this way a lot of
other strings will also be accepted.

Therefore, accurate way is draw another state. Declare the new


state initial as well as final. Connect the new state with the states
originally connected with the old start state with the same
transitions as the old start state. Newly drawn diagram will be an
NFA representing the language closure of the given FA

8. How Moore And Mealy Machine Works In Computer


Memory What Is Their Importance In Computing ?

Mealy & Moore Machines work in computing as incrementing


machine & 1’s complement machine etc. These operations as
basic computer operations so these machines are very important.

9. What Is The Significance Of Pumping Lemma Ii ?

The significance of 2nd version of ‘pumping lemma’ is that there


are some infinite non regular languages like PALINDROME we can
built FA that can accept there certain words but if we increase the
length of their words that FA don’t accept these words so by
pumping lemma version I it is very difficult to prove them non
regular but with the second version we can prove that a language
is Non regular even it’s some words may be accepted by some
FA’s.

10. Moore And Mealy Machine?

In order to run a string on a Mealy or Moore machine, you can


take directions from transition table. Running string on Mealy or
Moore machine is similar to running string on a FA. For example, if
want to run abba on the machine, take start from initial state.
Check what is the transition for a, what state it goes. After that
check what is the path of b from that state and so on. In this way
you will be able to run whole of the string. Note that there is no
final state in Mealy or Moore machine. So there is no case of
acceptance or rejection of string. You just have to determine what
the output is. I hope that will clear your mind for further
clarification please listens to your lecture carefully.

The string is taken for the testing purposes. You can take any sort
of string and determine its output using machine.

You might also like