On this page:
1 A Context-Free Language?
2 Inductive Proof Involving CFG Derivations
3 A Pushdown Automata (PDA)

Homework 7🔗

Last updated: Thu, 12 Nov 2026 10:36:23 -0500

Out: Thu Oct 29, 12:30pm EDT Due: Thu Nov 05, 12:30pm EDT

Note: Assignments are not officially "released" until—and are subject to change without notice up to—the indicated "Out" date and time. If an assignment is posted early, students may look ahead but are responsible for ensuring that they are always working with the most recent version of the homework.

This assignment explores context-free languages.

Homework Problems

  1. A Context-Free Language? (18 points)

  2. Inductive Proof Involving CFG Derivations (20 points)

  3. A Pushdown Automata (PDA) (20 points)

  4. README (2 point)

Total: 60 points

Submitting

Submit your solution to this assignment in Gradescope hw7. Please assign each page to the correct problem and make sure your solutions are legible.

A submission must also include a README containing the required information.

1 A Context-Free Language?🔗

Here is a language whose strings resemble simple Python programs.

\mathit{PY}_{420} = \left\{\texttt{if:}\!\hookleftarrow\!\diamond^*\texttt{print}\diamond 1\hookleftarrow\texttt{el:}\!\hookleftarrow\!\diamond^*\texttt{print}\diamond 2\mid\diamond\textrm{s after "if" must match those after "else"}\right\}

\Sigma = \left\{\texttt{if:},\texttt{el:},\texttt{print},\hookleftarrow,1,2,\diamond\right\} (in real-world grammars, terminal (i.e., alphabet) "symbols" can be, and often are, whole words)

Prove: \mathit{PY}_{420} IS-A Context-free Language (CFL)

Your proof must use correct proof syntax and constructors from this semester, and must use the CFG representation of CFLs.

2 Inductive Proof Involving CFG Derivations🔗

Imagine we wish to prove the following statement for string derivations using some CFG G=\left\langle V,\Sigma,R,S\right\rangle:

IF \alpha\Rightarrow_G^*\beta THEN \gamma_1\alpha\gamma_2\Rightarrow_G^*\gamma_1\beta\gamma_2

where \alpha,\beta,\gamma_1,\gamma_2\in (V\cup\Sigma)^*

In other words, if a grammar G can derive a string, then it can derive the same string as a substring in a larger string.

  • Prove the following Lemma Statement \mathrm{HW72a}: \textrm{IF }\alpha\Rightarrow_G\beta\textrm{ THEN }\gamma_1\alpha\gamma_2\Rightarrow_G\gamma_1\beta\gamma_2 You will need to use the "Definition of \Rightarrow_G", the single-step derivation arrow, as a Justification in the proof. (Note this Lemma Statement, which uses the single-step arrow is unrelated to the main statement above, so the multi-step arrow \Rightarrow_G^* should not appear in this proof). This is a very straightforward and short proof so anything longer than a few lines is probably on the wrong track

  • Now use \mathrm{HW72a} to prove the main statement above.

    Since \Rightarrow_G^* is a recursive defintion, the proof must also be recursive, i.e., you must use proof by induction.

    Make sure your proof uses the correct proof syntax and constructors from this semester.

3 A Pushdown Automata (PDA)🔗

For the following PDA state diagram:

  1. Give a formal description of this PDA. Make sure to include all the necessary components.

  2. Give two strings that are in the language recognized by this PDA. For each of these strings, give a sequence of configurations that represents an accepting computation for the PDA. Each should take a different path in the machine and they should end in state q_7.

  3. Give two strings that are not in the language recognized by this PDA.

  4. Give a CFG for the language recognized by this PDA (this problem is easier if you break it down into smaller problems) (alternatively, if you use the PDA-to-CFG conversion algorithm from lecture / the textbook that would work but could be a much more complicated approach, so make sure your answer is clear and understandable if you take this approach).