Unit 4 - Practice Quiz

CSE322 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which of the following describes the formal definition of a Context-Free Grammar (CFG)?

A. A 4-tuple
B. A 4-tuple
C. A 5-tuple
D. A 7-tuple

2 In the Chomsky Hierarchy, Context-Free Languages (CFLs) are classified as which type of language?

A. Type-0
B. Type-1
C. Type-2
D. Type-3

3 Which of the following correctly defines the language generated by a Context-Free Grammar ?

A.
B.
C.
D.

4 What is a Leftmost Derivation (LMD) in a Context-Free Grammar?

A. A derivation where the rightmost non-terminal is always replaced first.
B. A derivation where all non-terminals are replaced simultaneously.
C. A derivation where the leftmost non-terminal is always replaced at each step.
D. A derivation that only uses left-recursive production rules.

5 If represents a valid derivation in a CFG, what is called if it contains both variables and terminals?

A. A parse tree
B. A terminal string
C. A sentential form
D. A regular expression

6 If a sentential form is derived using exclusively a rightmost derivation, what is it specifically called?

A. A left-sentential form
B. A right-sentential form
C. A terminal string
D. A canonical sentence

7 When is a Context-Free Grammar considered ambiguous?

A. If it contains left-recursive rules.
B. If there exists a string in the language that has more than one leftmost derivation or more than one parse tree.
C. If it generates an infinite language.
D. If it has both nullable and unit productions.

8 Consider the grammar . Which of the following statements is true?

A. The grammar is unambiguous.
B. The grammar is ambiguous because the string 'aaa' has multiple parse trees.
C. The grammar generates the language .
D. The grammar is in Chomsky Normal Form.

9 What does it mean for a Context-Free Language to be 'inherently ambiguous'?

A. Every string in the language has multiple parse trees.
B. The language can only be generated by a regular grammar.
C. Every Context-Free Grammar that generates the language is ambiguous.
D. The language contains the empty string .

10 Is the problem of determining whether an arbitrary Context-Free Grammar is ambiguous decidable?

A. Yes, using the Pumping Lemma.
B. Yes, using the CYK algorithm.
C. No, the problem is formally undecidable.
D. No, but it can be decided if the grammar is in Greibach Normal Form.

11 Which of the following strings is NOT derivable from the grammar ?

A.
B.
C.
D.

12 What is the primary application of Context-Free Grammars in computer science?

A. Lexical analysis and token generation
B. Syntax analysis (parsing) in compilers
C. Network routing algorithms
D. Database schema indexing

13 Which standard format is used to represent Context-Free Grammars in the design of programming languages?

A. Regular Expressions (RE)
B. Backus-Naur Form (BNF)
C. Turing Machine state diagrams
D. Deterministic Finite Automata (DFA)

14 Which popular parser generator tool directly utilizes Context-Free Grammars to generate C code for a parser?

A. Lex
B. Grep
C. YACC (Yet Another Compiler Compiler)
D. Awk

15 In the context of the Pumping Lemma for Context-Free Languages, a string is divided into how many parts?

A. 3 parts ()
B. 4 parts ()
C. 5 parts ()
D. 6 parts ()

16 According to the Pumping Lemma for Context-Free Languages, which of the following conditions must hold for the decomposition ?

A. and
B. and
C. and
D. and

17 Which of the following is the 'pumped' string in the Pumping Lemma for Context-Free Languages?

A.
B.
C.
D.

18 What is the primary purpose of the Pumping Lemma for Context-Free Languages?

A. To prove that a grammar is ambiguous.
B. To convert a grammar into Chomsky Normal Form.
C. To prove that a language is NOT context-free.
D. To find the shortest string generated by a CFG.

19 Which of the following languages is a classic example of a language that is NOT context-free, often proven using the Pumping Lemma?

A.
B.
C.
D.

20 What defines a Null () production in a Context-Free Grammar?

A. A production of the form where is a terminal.
B. A production of the form .
C. A production where the start symbol is not used.
D. A production of the form where is a single variable.

21 What is a Unit production in a Context-Free Grammar?

A. A rule that derives a single terminal string: .
B. A rule that derives the empty string: .
C. A rule where the right-hand side is exactly one non-terminal: .
D. A rule that contains exactly one terminal and one non-terminal.

22 A variable in a CFG is called a 'useless symbol' if it satisfies which of the following conditions?

A. It is only reachable from the start symbol.
B. It does not participate in the derivation of any string of terminals.
C. It derives the empty string .
D. It appears on the left side of a unit production.

23 When eliminating useless symbols from a CFG, what is the correct order of the two main steps to ensure all useless symbols are properly removed?

A. First eliminate non-reachable symbols, then eliminate non-generating symbols.
B. First eliminate non-generating symbols, then eliminate non-reachable symbols.
C. First eliminate unit productions, then non-reachable symbols.
D. The order does not matter.

24 What is the recommended standard order for the three simplification steps of a Context-Free Grammar?

A. Eliminate useless symbols Eliminate unit productions Eliminate -productions
B. Eliminate -productions Eliminate unit productions Eliminate useless symbols
C. Eliminate unit productions Eliminate -productions Eliminate useless symbols
D. Eliminate useless symbols Eliminate -productions Eliminate unit productions

25 In a CFG, a variable is termed 'nullable' if it meets which condition?

A. It cannot derive any string.
B.
C.
D. , where is a terminal.

26 Consider a grammar with the production , where both and are nullable variables. When eliminating -productions, which new productions must be added for ?

A.
B.
C.
D.

27 How is a unit production eliminated from a grammar?

A. By replacing it with .
B. By adding the rule for every non-unit rule .
C. By merging the variables and into a single variable.
D. By simply deleting it and making no other changes.

28 Which of the following best defines a 'reduced grammar'?

A. A grammar with only one production rule per non-terminal.
B. A grammar in which there are no unit productions, no -productions, and no useless symbols.
C. A grammar that has been converted to Chomsky Normal Form.
D. A grammar that generates a finite language.

29 What is the specific format of production rules in Chomsky Normal Form (CNF)?

A. or
B. or
C. where is a string of variables
D. or

30 If a string of length () is generated by a grammar in Chomsky Normal Form, exactly how many steps are in its derivation?

A.
B.
C.
D.

31 What structural property does the parse tree of a string derived from a CFG in Chomsky Normal Form possess?

A. It is a left-skewed tree.
B. It is a strictly binary tree (each internal node has exactly two children, except nodes leading to terminals).
C. It has a maximum depth of 3.
D. It contains no terminal nodes.

32 Which dynamic programming algorithm relies on the grammar being in Chomsky Normal Form to check string membership in a CFL?

A. Dijkstra's Algorithm
B. CYK (Cocke-Younger-Kasami) Algorithm
C. Earley Parser
D. KMP Algorithm

33 What is the maximum number of variables on the right-hand side of a production rule in Chomsky Normal Form?

A. 1
B. 2
C. 3
D. Any number

34 What is the specific format of production rules in Greibach Normal Form (GNF)?

A. or
B. , where is a single terminal and is a string of zero or more variables.
C. or
D. , where is a terminal and is a string of variables.

35 If a string of length is generated by a grammar in Greibach Normal Form, exactly how many derivation steps are required?

A.
B.
C.
D.

36 Before converting a Context-Free Grammar into Greibach Normal Form, which structural issue MUST be eliminated from the grammar?

A. Right recursion
B. Left recursion
C. Chomsky Normal Form rules
D. Terminal symbols

37 Which of the following rules is an example of immediate left recursion?

A.
B.
C.
D.

38 Context-Free Languages are closed under which of the following operations?

A. Intersection and Complement
B. Union, Concatenation, and Kleene Star
C. Intersection only
D. Complement only

39 If is a Context-Free Language and is a Regular Language, what can be said about ?

A. It is always a Regular Language.
B. It is always a Context-Free Language.
C. It is neither regular nor context-free.
D. It is undecidable.

40 Greibach Normal Form (GNF) is particularly useful for demonstrating the equivalence between Context-Free Grammars and which computational model?

A. Deterministic Finite Automata (DFA)
B. Pushdown Automata (PDA)
C. Linear Bounded Automata (LBA)
D. Turing Machines (TM)

41 When eliminating immediate left recursion of the form , which new set of productions correctly replaces it? (Assume is a new variable)

A. and
B. and
C. and
D.

42 What is the 'yield' of a parse tree?

A. The set of all non-terminals used in the tree.
B. The height of the longest branch in the tree.
C. The concatenation of all the leaves of the tree from left to right.
D. The root symbol of the tree.

43 Which of the following grammars generates the language of all palindromes over the alphabet ?

A.
B.
C.
D.

44 Which of the following is true regarding deterministic vs non-deterministic Context-Free Languages?

A. Every Context-Free Language is deterministic.
B. Deterministic CFLs are exactly the languages accepted by Deterministic Pushdown Automata (DPDA).
C. There is no difference between deterministic and non-deterministic CFLs.
D. Deterministic CFLs can only be generated by regular expressions.

45 If and are Context-Free Languages, which operation is NOT guaranteed to produce a Context-Free Language?

A.
B.
C.
D.

46 Consider the CFG: , , . What is the language generated by this grammar?

A.
B.
C.
D.

47 If a CFG is simplified to eliminate null productions, which string might be accidentally removed from its language if not handled carefully?

A. Any string of length 1
B. The empty string
C. Strings containing only variables
D. Strings of infinite length

48 What is the primary benefit of converting a Context-Free Grammar into Chomsky Normal Form (CNF)?

A. It minimizes the number of production rules.
B. It allows the grammar to be parsed unambiguously by default.
C. It restricts the grammar so that algorithmic parsing (like CYK) and theoretical proofs become simpler.
D. It converts the language into a regular language.

49 Which component is missing from this partial definition of a context-free rule: 'The left-hand side of a production rule must consist of...'?

A. At least one terminal and one non-terminal.
B. Exactly one variable (non-terminal).
C. A string of terminals.
D. Any sequence of variables and terminals.

50 What type of derivation generates the tree nodes in a depth-first, left-to-right manner?

A. Rightmost derivation
B. Leftmost derivation
C. Bottom-up derivation
D. Parallel derivation