Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 4 MCQsCONTEXT- FREE LANGUAGES
CSE322 ·
50 questions. Pick an option to check it.
Which of the following describes the formal definition of a Context-Free Grammar (CFG)?
Not quite. Try another option.
Answer: A 4-tuple
A Context-Free Grammar is formally defined as a 4-tuple , where is a set of variables (non-terminals), is a set of terminals, is a set of production rules, and is the start symbol.
Question 2 of 50
In the Chomsky Hierarchy, Context-Free Languages (CFLs) are classified as which type of language?
Not quite. Try another option.
Answer: Type-2
In the Chomsky Hierarchy, Type-2 languages represent Context-Free Languages, which are generated by Context-Free Grammars.
Question 3 of 50
Which of the following correctly defines the language generated by a Context-Free Grammar ?
Not quite. Try another option.
Answer:
The language generated by a CFG, , consists of all strings of terminals () that can be derived from the start symbol in zero or more steps ().
Question 4 of 50
What is a Leftmost Derivation (LMD) in a Context-Free Grammar?
Not quite. Try another option.
Answer: A derivation where the leftmost non-terminal is always replaced at each step.
In a Leftmost Derivation (LMD), the leftmost variable (non-terminal) in the current sentential form is always the one chosen to be replaced by applying a production rule.
Question 5 of 50
If represents a valid derivation in a CFG, what is called if it contains both variables and terminals?
Not quite. Try another option.
Answer: A sentential form
Any string of variables and/or terminals that can be derived from the start symbol is called a sentential form.
Question 6 of 50
If a sentential form is derived using exclusively a rightmost derivation, what is it specifically called?
Not quite. Try another option.
Answer: A right-sentential form
A sentential form that occurs during a rightmost derivation is formally known as a right-sentential form.
Question 7 of 50
When is a Context-Free Grammar considered ambiguous?
Not quite. Try another option.
Answer: If there exists a string in the language that has more than one leftmost derivation or more than one parse tree.
A grammar is ambiguous if there is at least one string in its language that can be generated by two or more distinct leftmost derivations (which corresponds to having two or more distinct parse trees).
Question 8 of 50
Consider the grammar . Which of the following statements is true?
Not quite. Try another option.
Answer: The grammar is ambiguous because the string 'aaa' has multiple parse trees.
The grammar is ambiguous because strings like 'aaa' can be derived in multiple ways, yielding different parse trees (e.g., grouping either left or right).
Question 9 of 50
What does it mean for a Context-Free Language to be 'inherently ambiguous'?
Not quite. Try another option.
Answer: Every Context-Free Grammar that generates the language is ambiguous.
A language is inherently ambiguous if there is no unambiguous grammar that can generate it; every valid CFG for this language will contain ambiguity.
Question 10 of 50
Is the problem of determining whether an arbitrary Context-Free Grammar is ambiguous decidable?
Not quite. Try another option.
Answer: No, the problem is formally undecidable.
It is a well-known theorem in formal language theory that determining whether an arbitrary Context-Free Grammar is ambiguous is an undecidable problem. No general algorithm exists to solve it.
Question 11 of 50
Which of the following strings is NOT derivable from the grammar ?
Not quite. Try another option.
Answer:
The grammar generates the language . The string does not fit this pattern, as all 'a's must precede all 'b's.
Question 12 of 50
What is the primary application of Context-Free Grammars in computer science?
Not quite. Try another option.
Answer: Syntax analysis (parsing) in compilers
Context-Free Grammars are extensively used in the syntax analysis phase of a compiler to specify the syntactic structure of programming languages and to build parsers.
Question 13 of 50
Which standard format is used to represent Context-Free Grammars in the design of programming languages?
Not quite. Try another option.
Answer: Backus-Naur Form (BNF)
Backus-Naur Form (BNF) is a metasyntax notation widely used to express Context-Free Grammars, specifically for the syntax of computing programming languages.
Question 14 of 50
Which popular parser generator tool directly utilizes Context-Free Grammars to generate C code for a parser?
Not quite. Try another option.
Answer: YACC (Yet Another Compiler Compiler)
YACC is a standard parser generator that takes a CFG specification (usually in a BNF-like format) and generates a syntax analyzer (parser) in C.
Question 15 of 50
In the context of the Pumping Lemma for Context-Free Languages, a string is divided into how many parts?
Not quite. Try another option.
Answer: 5 parts ()
The Pumping Lemma for CFLs states that any sufficiently long string in a CFL can be divided into five parts: .
Question 16 of 50
According to the Pumping Lemma for Context-Free Languages, which of the following conditions must hold for the decomposition ?
Not quite. Try another option.
Answer: and
The Pumping Lemma for CFLs requires that the middle portion has a length of at most the pumping length () and that the substrings and cannot be simultaneously empty ().
Question 17 of 50
Which of the following is the 'pumped' string in the Pumping Lemma for Context-Free Languages?
Not quite. Try another option.
Answer:
The lemma states that if is a CFL, then for any , the pumped string must also be in .
Question 18 of 50
What is the primary purpose of the Pumping Lemma for Context-Free Languages?
Not quite. Try another option.
Answer: To prove that a language is NOT context-free.
Like the Pumping Lemma for regular languages, the Pumping Lemma for CFLs is primarily used in proofs by contradiction to show that a specific language is NOT context-free.
Question 19 of 50
Which of the following languages is a classic example of a language that is NOT context-free, often proven using the Pumping Lemma?
Not quite. Try another option.
Answer:
The language requires counting and matching three elements equally, which exceeds the capabilities of a pushdown automaton (and thus CFGs). It is famously proven non-context-free using the Pumping Lemma.
Question 20 of 50
What defines a Null () production in a Context-Free Grammar?
Not quite. Try another option.
Answer: A production of the form .
A null production, or -production, is a rule that replaces a non-terminal with the empty string ().
Question 21 of 50
What is a Unit production in a Context-Free Grammar?
Not quite. Try another option.
Answer: A rule where the right-hand side is exactly one non-terminal: .
A unit production is a production rule of the form , where both and are single variables (non-terminals).
Question 22 of 50
A variable in a CFG is called a 'useless symbol' if it satisfies which of the following conditions?
Not quite. Try another option.
Answer: It does not participate in the derivation of any string of terminals.
A symbol is useless if it is non-generating (cannot derive a terminal string) or non-reachable (cannot be reached from the start symbol in any derivation). Therefore, it never appears in any successful derivation of a valid terminal string.
Question 23 of 50
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?
Not quite. Try another option.
Answer: First eliminate non-generating symbols, then eliminate non-reachable symbols.
To successfully remove all useless symbols, you must first find and eliminate all non-generating variables (and rules containing them). Then, from the remaining grammar, you find and eliminate all variables and terminals that are not reachable from the start symbol. Doing it in reverse can leave useless symbols.
Question 24 of 50
What is the recommended standard order for the three simplification steps of a Context-Free Grammar?
Not quite. Try another option.
Answer: Eliminate -productions Eliminate unit productions Eliminate useless symbols
The standard sequence to guarantee a fully simplified grammar without re-introducing bad rules is: 1) Eliminate -productions, 2) Eliminate Unit productions, 3) Eliminate Useless symbols.
Question 25 of 50
In a CFG, a variable is termed 'nullable' if it meets which condition?
Not quite. Try another option.
Answer:
A variable is nullable if it can derive the empty string in one or more steps ().
Question 26 of 50
Consider a grammar with the production , where both and are nullable variables. When eliminating -productions, which new productions must be added for ?
Not quite. Try another option.
Answer:
If and can derive , replacing combinations of and with yields , (when ), and (when ). We do not add unless itself is being evaluated as nullable at the root level, but strictly the RHS variations are .
Question 27 of 50
How is a unit production eliminated from a grammar?
Not quite. Try another option.
Answer: By adding the rule for every non-unit rule .
To eliminate a unit production , you find all non-unit productions of (e.g., ) and add the productions directly to .
Question 28 of 50
Which of the following best defines a 'reduced grammar'?
Not quite. Try another option.
Answer: A grammar in which there are no unit productions, no -productions, and no useless symbols.
A reduced CFG is one that has undergone simplification to remove all -productions (except possibly for the start symbol), all unit productions, and all useless symbols.
Question 29 of 50
What is the specific format of production rules in Chomsky Normal Form (CNF)?
Not quite. Try another option.
Answer: or
In Chomsky Normal Form (CNF), every production rule must be of the form (two variables) or (one terminal).
Question 30 of 50
If a string of length () is generated by a grammar in Chomsky Normal Form, exactly how many steps are in its derivation?
Not quite. Try another option.
Answer:
In CNF, deriving a string of length requires exactly rule applications of the form (to generate variables) and applications of the form (to convert variables to terminals). Total steps = .
Question 31 of 50
What structural property does the parse tree of a string derived from a CFG in Chomsky Normal Form possess?
Not quite. Try another option.
Answer: It is a strictly binary tree (each internal node has exactly two children, except nodes leading to terminals).
Because all non-terminal rules in CNF take the form , every internal node in the parse tree branching to variables has exactly two children. Terminals are single children ().
Question 32 of 50
Which dynamic programming algorithm relies on the grammar being in Chomsky Normal Form to check string membership in a CFL?
Not quite. Try another option.
Answer: CYK (Cocke-Younger-Kasami) Algorithm
The CYK algorithm is a standard parsing algorithm that determines whether a string can be generated by a CFG. It requires the grammar to be in Chomsky Normal Form.
Question 33 of 50
What is the maximum number of variables on the right-hand side of a production rule in Chomsky Normal Form?
Not quite. Try another option.
Answer: 2
In CNF, the allowed forms are or . Therefore, the maximum number of variables on the right side is exactly 2.
Question 34 of 50
What is the specific format of production rules in Greibach Normal Form (GNF)?
Not quite. Try another option.
Answer: , where is a single terminal and is a string of zero or more variables.
In Greibach Normal Form (GNF), every production rule must start with exactly one terminal, optionally followed by any number of non-terminals (variables): .
Question 35 of 50
If a string of length is generated by a grammar in Greibach Normal Form, exactly how many derivation steps are required?
Not quite. Try another option.
Answer:
In GNF, every production rule generates exactly one terminal symbol. Therefore, to generate a string of length , exactly derivation steps are required.
Question 36 of 50
Before converting a Context-Free Grammar into Greibach Normal Form, which structural issue MUST be eliminated from the grammar?
Not quite. Try another option.
Answer: Left recursion
Left recursion (e.g., ) prevents a grammar from being converted into GNF because GNF requires every rule to start with a terminal, consuming input on the left.
Question 37 of 50
Which of the following rules is an example of immediate left recursion?
Not quite. Try another option.
Answer:
Immediate left recursion occurs when a production rule has the same non-terminal on the left side and at the very beginning of the right side, such as .
Question 38 of 50
Context-Free Languages are closed under which of the following operations?
Not quite. Try another option.
Answer: Union, Concatenation, and Kleene Star
CFLs are closed under union, concatenation, and Kleene star operations. They are NOT closed under intersection or complementation.
Question 39 of 50
If is a Context-Free Language and is a Regular Language, what can be said about ?
Not quite. Try another option.
Answer: It is always a Context-Free Language.
The intersection of a Context-Free Language and a Regular Language is always a Context-Free Language. This is known as the closure property under regular intersection.
Question 40 of 50
Greibach Normal Form (GNF) is particularly useful for demonstrating the equivalence between Context-Free Grammars and which computational model?
Not quite. Try another option.
Answer: Pushdown Automata (PDA)
GNF is structurally very close to how a PDA operates. Because each rule generates exactly one terminal, it naturally mirrors a PDA consuming one input symbol per transition.
Question 41 of 50
When eliminating immediate left recursion of the form , which new set of productions correctly replaces it? (Assume is a new variable)
Not quite. Try another option.
Answer: and
The standard algorithm to eliminate immediate left recursion converts into right recursion: and .
Question 42 of 50
What is the 'yield' of a parse tree?
Not quite. Try another option.
Answer: The concatenation of all the leaves of the tree from left to right.
The yield of a parse tree is the string formed by reading the labels of the leaf nodes from left to right. This forms the sentential form or terminal string derived by the tree.
Question 43 of 50
Which of the following grammars generates the language of all palindromes over the alphabet ?
Not quite. Try another option.
Answer:
Palindromes read the same forwards and backwards. The rules and ensure symmetry. The rules handle the middle of odd-length and even-length palindromes.
Question 44 of 50
Which of the following is true regarding deterministic vs non-deterministic Context-Free Languages?
Not quite. Try another option.
Answer: Deterministic CFLs are exactly the languages accepted by Deterministic Pushdown Automata (DPDA).
Unlike finite automata, non-deterministic PDAs are strictly more powerful than deterministic PDAs. The languages accepted by DPDAs form a proper subset of all CFLs, called Deterministic Context-Free Languages (DCFLs).
Question 45 of 50
If and are Context-Free Languages, which operation is NOT guaranteed to produce a Context-Free Language?
Not quite. Try another option.
Answer:
CFLs are closed under union (), concatenation (), and Kleene Star (). They are NOT closed under intersection ().
Question 46 of 50
Consider the CFG: , , . What is the language generated by this grammar?
Not quite. Try another option.
Answer:
The variable generates one or more 'a's (). The variable generates one or more 'b's (). Concatenating them gives , which means any sequence of 'a's followed by any sequence of 'b's (at least one of each).
Question 47 of 50
If a CFG is simplified to eliminate null productions, which string might be accidentally removed from its language if not handled carefully?
Not quite. Try another option.
Answer: The empty string
If the original language contains the empty string , completely eliminating all -productions will remove from the language. To fix this, is typically allowed if doesn't appear on the right side.
Question 48 of 50
What is the primary benefit of converting a Context-Free Grammar into Chomsky Normal Form (CNF)?
Not quite. Try another option.
Answer: It restricts the grammar so that algorithmic parsing (like CYK) and theoretical proofs become simpler.
CNF imposes a strict structure ( or ) that standardizes parse trees as binary trees, making algorithms like CYK possible and derivation lengths highly predictable ().
Question 49 of 50
Which component is missing from this partial definition of a context-free rule: 'The left-hand side of a production rule must consist of...'?
Not quite. Try another option.
Answer: Exactly one variable (non-terminal).
By the definition of a Context-Free Grammar (Type-2), the left-hand side of every production rule must be exactly one single variable (non-terminal). This is what makes it 'context-free'.
Question 50 of 50
What type of derivation generates the tree nodes in a depth-first, left-to-right manner?
Not quite. Try another option.
Answer: Leftmost derivation
A leftmost derivation continually expands the leftmost non-terminal, naturally corresponding to building the parse tree in a depth-first, left-to-right order.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE322 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE322 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.