Draw the base (iteration 0) and first two iterations of the following fractal:
- Base: an (empty) square.
- Recursive step: Make each empty square a 3x3 grid (mark off 1/3 and 2/3 of each side and draw vertical and horizontal lines), and shade the middle square in the grid.
Group exercises
For this part of the lab, you will be working in groups of three. In the first part of the exercise, each of three people in the group picks one of the topics below, and solves the corresponding questions. Then, each of you will explain to two of your peers how you have solved these questions. Your explanation should be good enough that they can then solve similar questions on their own.
Topic 1: Recursive definitions of sets.
Give a recursive definition of the following sets (directly, without using grammars).
- Set of all non-empty even-length strings over $\{a,b,c\}$.
- Set of all even natural numbers (your base case should still be finite).
Topic 2: Grammars as recursive definitions of sets
Recall that a (context-free) grammar consists of rules of the form $A \to w$, where $A$ is a variable, and $w$ is a string of variables and terminals (possibly empty). For each of the following languages, define a grammar that produces this language.
- A language of all strings over $\{0, 1\}$ which end with 1.
- A language of all strings that contain at least two 0s.
Topic 3: Parse trees and derivations
Let a language over $\{0,1\}$ be defined by the grammar $S \to S00 | 0S0 | 1 | \lambda $, where $\lambda$ is an empty string.
- Give two examples of strings in the language (other than ones in subquestion below), and two examples of strings not in this language.
- Draw parse trees to derive "000000" and "01000".
Review after the group activity
Consider the language of all palindromes over $\{a,b,c\}$ (that is, a set of all strings that read the same forwards and back).
- Give two examples of strings in this language, and two examples not in this language.
- Give a recursive definition of all palindromes over $\{a,b,c\}$. Hint: an empty string is a palindrome, and they can be even or odd length.
- Give a grammar generating this language.
- Draw parse trees for a string $aabcbaa$ and $caaaac$.