Practice Midterm Solutions for Theory of Computation, Exams of Theory of Computation

Solutions to a practice midterm for a course on Theory of Computation. It includes questions on Deterministic Finite Automata, Context Free Grammar, and binary palindromes. formal descriptions of DFAs, pumping lemmas, and grammars, as well as proofs and justifications for certain language properties. It also includes a PDA construction for recognizing binary palindromes.

Typology: Exams

2021/2022

Uploaded on 05/11/2023

mikaell
mikaell 🇺🇸

4.6

(5)

249 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 of 6
Theory of Computation
Practice Midterm Solutions
Name: _______________________________________
Directions:
Answer the questions as well as you can. Partial credit will be given, so show your work where
appropriate. Try to be precise in your answers in order to maximize your points. Also make sure that your
answers to pumping lemma questions are sufficiently clear so that I can tell that your reasoning is correct.
Good luck.
Note: DFA = Deterministic Finite Automata NFA = Nondeterministic Finite Automata
PDA = Push-Down Automata CFG=Context Free Grammar
Here are the pumping lemmas:
If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of
length at least p, then s may be divided into 3 pieces, s = xyz, satisfying the following conditions:
1. For each i ≥0, xyiz A,
2. |y| > 0, and
3. |xy| ≤ p
pf3
pf4
pf5

Partial preview of the text

Download Practice Midterm Solutions for Theory of Computation and more Exams Theory of Computation in PDF only on Docsity!

Theory of Computation

Practice Midterm Solutions

Name: _______________________________________

Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be precise in your answers in order to maximize your points. Also make sure that your answers to pumping lemma questions are sufficiently clear so that I can tell that your reasoning is correct. Good luck. Note: DFA = Deterministic Finite Automata NFA = Nondeterministic Finite Automata PDA = Push-Down Automata CFG=Context Free Grammar Here are the pumping lemmas: If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of length at least p , then s may be divided into 3 pieces, s = xyz , satisfying the following conditions:

  1. For each i ≥0, xyiz  A,
  2. | y | > 0, and
  3. | xy | ≤ p
  1. Let M be the Deterministic Finite Automata (DFA) shown below a. Provide a formal description of M below ( 6 points) M = ({q0, q1, q2, q3}, {0, 1}, δ, q0, {q2}) or alternatively Q = {q0, q1, q2, q3}  = {0, 1} q0 = q F = {q2} In either case, you need to specify δ as: 0 1 q0 q1 q q1 q2 q q2 q3 q q3 q3 q b. In plain English, describe the language described by this DFA. In order to get full credit, you need to provide reasonably succinct description that ignores irrelevant considerations. Fill in the blank below. ( 3 points) The DFA shown above describes a language that contains exactly 2 0’s. c. Is the language described in part 1b a context-free language? Circle “Yes” or “No” and then briefly justify your answer. (3 points) Yes No Because the language is defined by a DFA M, it is a regular language. A regular language is always a context free language. That is because a CFL is defined by a PDA and a PDA is a NFA with a stack—so it includes all NFA’s.

q0 q q q

  1. Draw the NFA that recognizes the language where w contains the substring 0101. Do this using 5 states and assuming a binary alphabet.
  2. Your friend Brian is trying to prove that the language ww-R, the language of palindromes, is not regular. For pumping length p he chooses the string S = 01 p 1 p 0, which is a palindrome. Can he use the pumping lemma for regular languages to prove that this language is not regular? Circle one: Yes No Now explain why below: Although the language is not regular, you can find an assignment of xyz that can be pumped. Try the following: x = 0, y = 1, z = 1 p- 1 1 p 0 When we pump it, we get something of the form 01 x

0, where x  2p. This is always a

palindrome (note that it does not matter if x is even or odd). Note that if you chose 1 p 01 p then you cannot pump it.

  1. Prove or disprove the following statements. Assume that  = {0,1} a. 0 n 1 2n^ is regular, n  1 . Circle one: Prove (statement true) Disprove (statement false) Prove or disprove below: If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into 3 pieces, s = xyz, satisfying the 3 pumping lemma conditions. Let S = 0 p 1 2p By condition 2, y may only contain 0’s. Assuming xyz is in the language, then xyyz will not be in the language since it will yield 0p+1 1 2p. Hence the language is not regular. Disproved. 0, 1 0, 1 q1 0 0 1 01 0 010 1 0101

b. 0 n 1 2n^ is context-free, n  1 Circle one: Prove (statement true) Disprove (statement false) Prove or disprove below: Proof by construction 1:

S → 0 R

R → 0R11 | 

Proof by construction 2: Use a PDA and start in a state that pushes a 0 on the stack for each 0 read. Once the first 1 is seen then move into another state that pops a 0 from the stack for every second 1 read. If you run out of 1’s when the stack is not empty or if you see any more 0’s, then reject. Accept if you run out of input, are in the state where you just popped off a 0, and if the stack is empty.

  1. Provide a Context Free grammar that generates the language 001. S → AB A → 0A| B → 1B|ε
  2. Provide a context free grammar that generates L = {anbm: n m} S → AS 1 | S 1 B // First rule generates string with more a’s; second with more b’s S1 → aS 1 b | ɛ // adds equal numbers of a’s and b’s in proper order A → aA|a // generates one or more a’s B →bB|b // generates one or more b’s