Unit 4: CONTEXT- FREE LANGUAGES - 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 7-tuple
B. A 5-tuple
C. A 4-tuple
D. A 4-tuple

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

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

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

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

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

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

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

7 When is a Context-Free Grammar considered ambiguous?

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

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

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

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. The language contains the empty string .
D. Every Context-Free Grammar that generates the language is ambiguous.

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

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

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. Database schema indexing
B. Lexical analysis and token generation
C. Network routing algorithms
D. Syntax analysis (parsing) in compilers

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

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

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

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

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

A. 5 parts ()
B. 6 parts ()
C. 3 parts ()
D. 4 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 find the shortest string generated by a CFG.
C. To convert a grammar into Chomsky Normal Form.
D. To prove that a language is NOT context-free.

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 where the start symbol is not used.
C. A production of the form where is a single variable.
D. A production of the form .

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

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

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

A. It derives the empty string .
B. It is only reachable from the start symbol.
C. It does not participate in the derivation of any string of terminals.
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 unit productions, then non-reachable symbols.
B. First eliminate non-generating symbols, then eliminate non-reachable symbols.
C. First eliminate non-reachable symbols, then eliminate non-generating 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 -productions Eliminate unit productions
B. Eliminate -productions Eliminate unit productions Eliminate useless symbols
C. Eliminate useless symbols Eliminate unit productions Eliminate -productions
D. Eliminate unit productions Eliminate -productions Eliminate useless symbols

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

A.
B.
C. It cannot derive any string.
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 simply deleting it and making no other changes.
B. By adding the rule for every non-unit rule .
C. By replacing it with .
D. By merging the variables and into a single variable.

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

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

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

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

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 strictly binary tree (each internal node has exactly two children, except nodes leading to terminals).
B. It is a left-skewed tree.
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. KMP Algorithm
B. Earley Parser
C. CYK (Cocke-Younger-Kasami) Algorithm
D. Dijkstra's Algorithm

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

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

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

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

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. Chomsky Normal Form rules
B. Right recursion
C. Left recursion
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. Complement only
B. Union, Concatenation, and Kleene Star
C. Intersection only
D. Intersection and Complement

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 undecidable.
C. It is always a Context-Free Language.
D. It is neither regular nor context-free.

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

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

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

A.
B. and
C. and
D. and

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

A. The root symbol of the tree.
B. The set of all non-terminals used in the tree.
C. The concatenation of all the leaves of the tree from left to right.
D. The height of the longest branch in 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 can only be generated by regular expressions.
C. Deterministic CFLs are exactly the languages accepted by Deterministic Pushdown Automata (DPDA).
D. There is no difference between deterministic and non-deterministic CFLs.

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. The empty string
B. Strings containing only variables
C. Strings of infinite length
D. Any string of length 1

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

A. It converts the language into a regular language.
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 minimizes the number of production rules.

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. Any sequence of variables and terminals.
D. A string of terminals.

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

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