Unit 4 PDF
Unit 4 PDF
Unit 4 PDF
8. The minimum number of productions required to produce a language consisting of palindrome strings
over ∑={a,b} is
a) 3
b) 7
c) 5
d) 6
View Answer
Answer: c
Explanation: The grammar which produces a palindrome set can be written as:
S-> aSa | bSb | e | a | b
L={e, a, b, aba, abbbaabbba…..}
9. Which of the following statement is correct?
a) All Regular grammar are context free but not vice versa
b) All context free grammar are regular grammar but not vice versa
c) Regular grammar and context free grammar are the same entity
d) None of the mentioned
View Answer
Answer: a
Explanation: Regular grammar is a subset of context free grammar and thus all regular grammars are
context free.
10. Are ambiguous grammar context free?
a) Yes
b) No
View Answer
Answer: a
Explanation: A context free grammar G is ambiguous if there is atleast one string in L(G) which has two or
more distinct leftmost derivations.
Automata Theory Questions and Answers – The Language of a Grammar, Inferences and Ambiguity
This set of Automata Theory Problems focuses on “The Language of a Grammar, Inferences and
Ambiguity”.
a) true
b) partially true
c) false
d) none of the mentioned
View Answer
Answer: a
Explanation: We apply the productions of a CFG to infer that certain strings are in a language of certain
variable.
advertisement
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Sentential
Forms”.
1. State true or false:
Statement: Every right-linear grammar generates a regular language.
a) True
b) False
View Answer
Answer: a
Explanation: A CFG is said to right linear if each production body has at most one variable, and that
variable is at the right end. That is, all productions of a right linear grammar are of the form A->wB or A-
>w, where A and B are variables while w is some terminal.
2. What the does the given CFG defines?
S->aSbS|bSaS|e and w denotes terminal
a) wwr
b) wSw
c) Equal number of a’s and b’s
d) None of the mentioned
View Answer
Answer: c
Explanation: Using the derivation approach, we can conclude that the given grammar produces a
language with a set of string which have equal number of a’s and b’s.
3. If L1 and L2 are context free languages, which of the following is context free?
a) L1*
b) L2UL1
c) L1.L2
d) All of the mentioned
View Answer
Answer: d
Explanation: The following is a theorem which states the closure property of context free languages which
includes Kleene operation, Union operation and Dot operation.
4. For the given Regular expression, the minimum number of variables including starting variable required
to derive its grammar is:
(011+1)*(01)*
a) 4
b) 3
c) 5
d) 6
View Answer
Answer: c
Explanation: The grammar can be written as:
S->BC
B->AB|ε
A->011|1
C->DC|ε
D->01
5. For the given Regular expression, the minimum number of terminals required to derive its grammar is:
(011+1)*(01)*
a) 4
b) 3
c) 5
d) 6
View Answer
Answer: b
Explanation: The grammar can be written as:
S->BC
B->AB|ε
A->011|1
C->DC|ε
D->01
6. A grammar G=(V, T, P, S) is __________ if every production taken one of the two forms:
B->aC
B->a
a) Ambiguous
b) Regular
c) Non Regular
d) None of the mentioned
View Answer
Answer: b
Explanation: The following format of grammar is of Regular grammar and is a part of Context free
grammar i.e. like a specific form whose finite automata can be generated.
7. Which among the following is a CFG for the given Language:
L={x∈{0,1}*|number of zeroes in x=number of one’s in x}
a) S->e|0S1|1S0|SS
b) S->0B|1A|e A->0S B->1S
c) All of the mentioned
View Answer
Answer: c
Explanation: We can build context free grammar through different approaches, recursively defining the
variables and terminals inorder to fulfil the conditions.
advertisement
8. Which of the following languages are most suitable for implement context free languages ?
a) C
b) Perl
c) Assembly Language
d) None of the mentioned
View Answer
Answer: a
Explanation: The advantage of using high level programming language like C and Pascal is that they
allow us to write statements that look more like English.
9. Which among the following is the correct grammar for the given language?
L={x∈{0,1}*|number of zeroes in x¹number of one’s in x}
a) S-> 0|SS|1SS|SS1|S1S
b) S-> 1|0S|0SS|SS0|S0S
c) S-> 0|0S|1SS|SS1|S1S
d) None of the mentioned
View Answer
Answer: c
Explanation: L={0, 1, 00, 11, 001, 010,…}
The grammar can be framed as: S-> 0|0S|1SS|SS1|S1S
10. L={0i1j2k | j>i+k}
Which of the following satisfies the language?
a) 0111100
b) 011100
c) 0001100
d) 0101010
View Answer
Answer: a
Explanation: It is just required to put the value in the variables in the question and check if it satisfies or
not.
Automata Theory Questions and Answers – Construction and Yield of a Parse Tree
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Construction and
Yield of a Parse Tree”.
1. The most suitable data structure used to represent the derivations in compiler:
a) Queue
b) Linked List
c) Tree
d) Hash Tables
View Answer
Answer: c
Explanation: The tree, known as “Parse tree” when used in a compiler, is the data structure of choice to
represent the source program.
2. Which of the following statement is false in context of tree terminology?
a) Root with no children is called a leaf
b) A node can have three children
c) Root has no parent
d) Trees are collection of nodes, with a parent child relationship
View Answer
Answer: a
Explanation: A node has atmost one parent, drawn above the node, and zero or more children drawn
below. Lines connect parents to children. There is one node, one root, that has no parent; this node
appears to be at the top of the tree. Nodes with no children are called leaves. Nodes that are not leaves
are called interior nodes.
3. In which order are the children of any node ordered?
a) From the left
b) From the right
c) Arbitrarily
d) None of the mentioned
View Answer
Answer: a
Explanation: The children of a node are ordered from the left and drawn so. If N is to the left of node M,
then all the descendents of N are considered to be to the left of all the descendents of M.
4. Which among the following is the root of the parse tree?
a) Production P
b) Terminal T
c) Variable V
d) Starting Variable S
View Answer
Answer: d
Explanation: The root is labelled by the start symbol. All the leaves are either labelled by a a terminal or
with e.
5. For the expression E*(E) where * and brackets are the operation, number of nodes in the respective
parse tree are:
a) 6
b) 7
c) 5
d) 2
View Answer
Answer: b
Explanation:
6. The number of leaves in a parse tree with expression E*(E) where * and () are operators
a) 5
b) 2
c) 4
d) 3
View Answer
Answer: a
Explanation:
7. Which of the following does the given parse tree correspond to?
a) P->1100
b) P->0110
c) P->1100ε
d) P->0101
View Answer
Answer: b
Explanation: The following is a parse tree for the production 0110 over {0,1}*.
advertisement
This set of Automata Theory Question Bank focuses on “Inferences to Trees, Trees to Derivations”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Applications –
Parsers”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “YACC Parser
Generator”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Markup
Languages”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Ambiguous
Grammar”.
1. A CFG is ambiguous if
a) It has more than one rightmost derivations
b) It has more than one leftmost derivations
c) No parse tree can be generated for the CFG
d) None of the mentioned
View Answer
Answer: b
Explanation: A context free grammar is ambiguous if it has more than one parse tree generated or more
than one leftmost derivations. An unambiguous grammar is a context free grammar for which every valid
string has a unique leftmost derivation.
2. Which of the following are always unambiguous?
a) Deterministic Context free grammars
b) Non-Deterministic Regular grammars
c) Context sensitive grammar
d) None of the mentioned
View Answer
Answer: a
Explanation: Deterministic CFGs are always unambiguous , and are an important subclass of
unambiguous CFGs; there are non-deterministic unambiguous CFGs, however.
3. A CFG is not closed under
a) Dot operation
b) Union Operation
c) Concatenation
d) Iteration
View Answer
Answer: d
Explanation: The closure property of a context free grammar does not include iteration or kleene or star
operation.
4. Which of the following is an real-world programming language ambiguity?
a) dangling else problem
b) halting problem
c) maze problem
d) none of the mentioned
View Answer
Answer: a
Explanation: Dangling else problem: In many languages,the else in an if-then-else statement is optional,
which results into nested conditionals being ambiguous, at least in terms of the CFG.
5. Which of the following is a parser for an ambiguous grammar?
a) GLR parser
b) Chart parser
c) All of the mentioned
d) None of the mentioned
View Answer
Answer: c
Explanation: GLR parser: a type of parser for non deterministic and ambiguous grammar
Chart parser: aa type of parser for ambiguous grammar.
6. A language that admits only ambiguous grammar:
a) Inherent Ambiguous language
b) Inherent Unambiguous language
c) Context free language
d) Context Sensitive language
View Answer
Answer: a
Explanation: A context free language for which no unambiguous grammar exists, is called Inherent
ambiguous language.
7. Which of the following is an example of inherent ambiguous language?
a) {an|n>1}
b) {anbncmdm| n,m > 0}
c) {0n1n|n>0}
d) None of the mentioned
View Answer
Answer: b
Explanation: This set is context-free, since the union of two context-free languages is always context free.
advertisement
This set of Automata Theory Assessment Questions and Answers focuses on “CFG-Eliminating Useless
Symbols”.
1. Suppose A->xBz and B->y, then the simplified grammar would be:
a) A->xyz
b) A->xBz|xyz
c) A->xBz|B|y
d) none of the mentioned
View Answer
Answer: a
Explanation: For the first step, substitute B in first production as it only produces terminal and remove B
production as it has already been utilized.
We get A->xBz|xyz and now, as B has no production, we eliminate the terms which hold the variable B,
thus the answer remain A->xyz.
2. Given Grammar: S->A, A->aA, A->e, B->bA
Which among the following productions are Useless productions?
a) S->A
b) A->aA
c) A->e
d) B->bA
View Answer
Answer: d
Explanation: Some derivations are not reachable from the starting variable. As B is not reachable from
the starting variable, it is a useless symbol and thus, can be eliminated.
3. Given:
S->…->xAy->…->w
if ____________, then A is useful, else useless symbol.
a) A is a non terminal
b) A is a terminal
c) w Î L
d) w Ë L
View Answer
Answer: c
Explanation: Whatever operation we perform in intermediate stages, if the string produced belongs to the
language, A is termed as useful and if not, not a useful variable.
4. Given:
S->aSb
S->e
S-> A
A->aA
B->C
C->D
The ratio of number of useless variables to number of useless production is:
a) 1
b) 3/4
c) 2/3
d) 0
View Answer
Answer: a
Explanation: A, B, C, D are the useless symbols in the given grammar as they never tend to lead to a
terminal. The productions S-> A, A->aA, B->C, C->D are also termed as useless production as they will
never produce a string to the grammar.
5. Given grammar G:
S->aS|A|C
A->a
B->aa
C->aCb
Find the set of variables thet can produce strings only with the set of terminals.
a) {C}
b) {A,B}
c) {A,B,S}
d) None of the mentioned
View Answer
Answer: c
Explanation: First step: Make a set of variables that directly end up with a terminal
Second step: Modify the set with variables that produce the elements of above
generated set.
The rest variables are termed as useless.
6. Given grammar:
S->aS|A
A->a
B->aa
Find the number of variables reachable from the Starting Variable?
a) 0
b) 1
c) 2
d) None of the mentioned
View Answer
Answer: b
Explanation: Use a dependency graph to find which variable is reachable and which is not.
7. Inorder to simplify a context free grammar, we can skip the following operation:
a) Removal of null production
b) Removal of useless symbols
c) Removal of unit productions
d) None of the mentioned
View Answer
Answer: d
Explanation: Inorder to simplify the grammar all of the process including the removal of null productions,
unit productions and useless symbols is necessary.
8. Given a Grammar G:
S->aA
A->a
A->B
B->A
B->bb
Which among the following will be the simplified grammar?
a) S->aA|aB, A->a, B->bb
b) S->aA|aB, A->B, B->bb
c) S->aA|aB, A->a, B->A
d) None of the emntioned
View Answer
Answer: a
Explanation: Step 1: Substitute A->B
Step 2: Remove B->B
Step 3: Substitute B->A
Step 4: Remove Repeated productions
9. Simplify the given grammar:
A-> a| aaA| abBc
B-> abba| b
10. In context to the process of removing useless symbols, which of the following is correct?
a) We remove the Nullable variables
b) We eliminate the unit productions
c) We eliminate products which yield no terminals
d) All of the mentioned
View Answer
Answer: c
Explanation: In the process of removal of useless symbols, we want to remove productions that can never
take part in any derivation
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Eliminating
Epsilon Productions”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Eliminating Unit
Productions”.
8. Given grammar G:
S-> ABA, A->aA|e, B-> bB|e
Eliminate e and unit productions. State the number of productions the starting variable holds?
a) 6
b) 7
c) 9
d) 5
View Answer
Answer: b
Explanation: After reduction the grammar looks like:
S->ABA| AB| BA| AA| Aa| a| bB| b
A->aA| a
B->bB| b
9. Given grammar G:
S-> A| B| C
A-> aAa| B
B-> bB|bb
C->aCaa|D
D->baD|abD|aa
Eliminate e and unit productions and state the number of variables left?
a) 5
b) 4
c) 3
d) 2
View Answer
Answer: 5
Explanation: The reduced production:
S->aAa| bB|bb aCaa| baD| abD| aa, A->aAa| bB| bb, B->bB| bb, C->aCaa| baD| abD| aa, D-> baD| abD|
aa
10. Which of the following variables in the given grammar is called live variable?
S->AB
A->a
a) S
b) A
c) B
d) None of the mentioned
View Answer
Answer: b
Explanation: Any variable A for which there is a production A-> x with x Ε Σ* is called live.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Chomsky Normal
Form”.
8. In which of the following, does the CNF conversion find its use?
a) CYK Algorithm
b) Bottom up parsing
c) Preprocessing step in some algorithms
d) All of the mentioned
View Answer
Answer: d
Explanation: Besides the theoretical significance of CNF, it conversion scheme is helpful in algorithms as
a preprocessing step, CYK algorithms and the bottom up parsing of context free grammars.
9. Let G be a grammar. When the production in G satisfy certain restrictions, then G is said to be in
___________.
a) restricted form
b) parsed form
c) normal form
d) all of the mentioned
View Answer
Answer: c
Explanation: When the production in G satisfy certain restrictions, then G is said to be in ‘normal form’.
10. Let G be a grammar: S->AB|e, A->a, B->b
Is the given grammar in CNF?
a) Yes
b) No
View Answer
Answer: a
Explanation: e is allowed in CNF only if the starting variable does not occur on the right hand side of the
derivation.
Automata Theory Questions and Answers – Pumping Lemma for Context Free Language
This set of Automata Theory Questions and Answers for Campus interviews focuses on “Pumping
Lemma for Context Free Language”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “CFL- Closure
Properties/Decision Properties”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “CFL- Other
Normal Forms”.
This set of Automata Theory Multiple Choice Questions & Answers (MCQs) focuses on “Intersection with
Regular Languages”.