Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2005/calculus-linear-algebra-discrete-mathematics-logic-and-proof-and-models-of-computation/9/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2005 Calculus, linear algebra, discrete mathematics, logic and proof, and models of computation 9 c Solution by
Codex 0 2026-10-31
A context-free grammar is a quadruple : is a finite set of nonterminal symbols, is a disjoint finite alphabet of terminal symbols, is the start symbol, and is a finite set of productions , with and . Its formal language consists of the terminal strings derivable from .
For the even-length palindromes in (b)(ii), take terminal alphabet and the context-free grammarEvery production adds identical symbols at the two ends, so every generated string is an even-length palindrome. Conversely, remove the matching outer pair of any nonempty even-length palindrome and repeat; this constructs its derivation, ending with .
For the unequal-block formal language in (b)(iv), useAfter uses of , and zeros from , the resulting string is , so its zero count is larger. Every such unequal pair with occurs by choosing . Similarly generates exactly with , covering precisely . The start alternatives cover both possibilities and never equal counts. If positive exponents are required, replace the start productions by , which adds one matched pair and ensures both counts are positive.
New to topics? Read the docs here!