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 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-2
C. Type-3
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 where the leftmost non-terminal is always replaced at each step.
C. A derivation that only uses left-recursive production rules.
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 regular expression
B. A sentential form
C. A parse tree
D. A terminal string

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 ambiguous because the string 'aaa' has multiple parse trees.
B. The grammar generates the language .
C. The grammar is in Chomsky Normal Form.
D. The grammar is unambiguous.

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

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

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

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

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. Syntax analysis (parsing) in compilers
D. Network routing algorithms

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

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

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

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

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

A. 3 parts ()
B. 6 parts ()
C. 5 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 language is NOT context-free.
B. To convert a grammar into Chomsky Normal Form.
C. To prove that a grammar is ambiguous.
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 .
B. A production of the form where is a terminal.
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 where the right-hand side is exactly one non-terminal: .
B. A rule that contains exactly one terminal and one non-terminal.
C. A rule that derives the empty string: .
D. A rule that derives a single terminal string: .

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

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

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-generating symbols, then eliminate non-reachable symbols.
B. First eliminate non-reachable symbols, then eliminate non-generating symbols.
C. The order does not matter.
D. First eliminate unit productions, then non-reachable symbols.

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 useless symbols Eliminate unit productions Eliminate -productions
C. Eliminate unit productions Eliminate -productions Eliminate useless symbols
D. Eliminate -productions Eliminate unit productions Eliminate useless symbols

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

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

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 simply deleting it and making no other changes.
D. By merging the variables and into a single variable.

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

A. A grammar that has been converted to Chomsky Normal Form.
B. A grammar with only one production rule per non-terminal.
C. A grammar in which there are no unit productions, no -productions, and no useless symbols.
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. 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 contains no terminal nodes.
B. It is a strictly binary tree (each internal node has exactly two children, except nodes leading to terminals).
C. It is a left-skewed tree.
D. It has a maximum depth of 3.

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

A. Earley Parser
B. CYK (Cocke-Younger-Kasami) Algorithm
C. KMP 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. 2
B. 1
C. Any number
D. 3

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. Terminal symbols
C. Left recursion
D. Chomsky Normal Form rules

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 always a Context-Free Language.
C. It is undecidable.
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. Turing Machines (TM)
B. Deterministic Finite Automata (DFA)
C. Pushdown Automata (PDA)
D. Linear Bounded Automata (LBA)

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.
C. and
D. and

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

A. The root symbol of 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 set of all non-terminals used 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. There is no difference between deterministic and non-deterministic CFLs.
B. Deterministic CFLs are exactly the languages accepted by Deterministic Pushdown Automata (DPDA).
C. Deterministic CFLs can only be generated by regular expressions.
D. Every Context-Free Language is deterministic.

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

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 minimizes the number of production rules.
D. It restricts the grammar so that algorithmic parsing (like CYK) and theoretical proofs become simpler.

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. Any sequence of variables and terminals.
B. Exactly one variable (non-terminal).
C. At least one terminal and one non-terminal.
D. A string of terminals.

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

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