← RGPV CS-501 Theory of Computation December 2025 Solved Question Paper
← RGPV CS-501 Theory of Computation May 2023 Solved Paper
Question
Explain context-free grammars and derivation trees.
Asked in: CS-501 | December 2025 | 4(a)
Define context-free grammar with an example.
Asked in: CS-501 | May 2023 | 5(b)
Answer
A context-free grammar is G=(V,Σ,P,S), where V is a finite set of variables, Σ a disjoint terminal alphabet, P a finite set of productions A→α with A∈V and α∈(V∪Σ)*, and S the start variable. A derivation replaces a variable by the right-hand side of a production. The generated language consists of terminal strings derivable from S.
Derivations and trees
A leftmost derivation always expands the leftmost variable; a rightmost derivation expands the rightmost variable. A parse tree has S at its root, variables at internal nodes, and terminals or ε at leaves. The ordered children of each internal node correspond to one production. Reading leaves left to right yields the generated word.
For S→SS | a, the word aa has derivation S⇒SS⇒aS⇒aa. The rightmost derivation S⇒SS⇒Sa⇒aa represents the same tree. Different expansion orders alone do not imply ambiguity. Ambiguity occurs when a word has two distinct parse trees, or equivalently two distinct leftmost derivations.
CFGs describe nested structures such as balanced parentheses and programming-language syntax. Pushdown automata recognize exactly context-free languages. Unlike regular grammars, CFGs can express unbounded nesting.

← RGPV CS-501 Theory of Computation December 2025 Solved Question Paper
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion