0% found this document useful (0 votes)
60 views4 pages

CS375 Sol7 2023f

This document provides the details of homework assignment 7 for the CS375 course. It includes 6 problems related to context-free grammars, pushdown automata, and Turing machines. Students are asked to fill in blanks in grammars, automata configurations, and Turing machine instructions to recognize specific formal languages. The homework is due on November 17, 2023 and solutions should be submitted as both a Word and PDF file with a specific naming convention.

Uploaded by

Seung Jun Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views4 pages

CS375 Sol7 2023f

This document provides the details of homework assignment 7 for the CS375 course. It includes 6 problems related to context-free grammars, pushdown automata, and Turing machines. Students are asked to fill in blanks in grammars, automata configurations, and Turing machine instructions to recognize specific formal languages. The homework is due on November 17, 2023 and solutions should be submitted as both a Word and PDF file with a specific naming convention.

Uploaded by

Seung Jun Lee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS375 Homework Assignment 7 Solution Set(40 points)

Due Date: November 17, 2023

1. (5 points; 1 point each blank)


The following given grammar is a left recursive grammar
S → Sbab | b | a
The language generated by this grammar is of the following form:

L = { bw, aw | w = (𝑏𝑎𝑏)𝑛 , 𝑛 𝜖 𝑁 }

This left recursive grammar can be transformed to a right recursive grammar as follows:
S → bB | aB

B → babB | Ʌ

This right recursive grammar is an LL( 1 ) grammar.

2. (6 points; 1 point each blank)


The following grammar is an indirect left recursive grammar
S → Ba | b B → Sb | a
Strings of the language generated by this grammar are of the following form:

L = { bw, aaw | w = (𝑏𝑎)𝑛 }

This indirect left recursive grammar can be transformed to a right recursive grammar as
follows:
S → | bB
aaB

B → baB | Ʌ

This right recursive grammar is an LL( 1 ) grammar.

3. (7 points)
In slide 41 of the notes “Context-free Languages and Pushdown Automata IV”, it is shown that the set
of LL(k) languages is a proper subset of the set of deterministic C-F languages (or see the following
figure). In particular, it points out that the language {𝑎𝑚 , 𝑎𝑛 𝑏 𝑛 | 𝑚, 𝑛 ∈ 𝑁 } is a deterministic C-F, but not
LL(k) for any k.
To show the language is not LL(k) for any k, note that a grammar for this language is

aA Ʌ aBb Ʌ

or

aAb Ʌ aB Ʌ
(4 points)
(you only need to answer one case here, either one). The language contains Ʌ as an element. Now
consider the case k = 1 and consider the input string ab. When the first symbol is scanned, we get an
‘a’. This information alone is not enough for us to make a proper choice. So we don’t even know what
to do with the first step in the parsing process.
For k = 2, if we consider the input string aabb, we face the same problem. For any k > 2, the input string
𝑎𝑘 𝑏 𝑘 would cause exactly the same problem. So this grammar is not LL(k) for any k.

On the other hand, by putting proper instructions into the blanks of the following figure, we get a
deterministic final-state PDA that accepts the language {𝑎𝑚 , 𝑎𝑛 𝑏 𝑛 | 𝑚, 𝑛 ∈ 𝑁 }.

𝑏, 𝑎
𝑝𝑜𝑝
𝑏, 𝑎
𝑝𝑜𝑝

Ʌ, 𝑋
𝑝𝑜𝑝

or

𝑏, 𝑎
𝑝𝑜𝑝
𝑏, 𝑎
𝑝𝑜𝑝

Ʌ, 𝑋
𝑛𝑜𝑝
(3 points)

(again, you only need to answer one case here, either one). Hence, this language is indeed
deterministic C-F, but not LL(k) for any k.
4. (4 points)
Fill out the following blanks for the instructions of a Turing machine that accepts the language
{𝑎𝑛 𝑏 | 𝑛 ∈ 𝑁}. Use smallest possible non-negative integers to represent the states of the TM.

0 1

5. (6 points)
Fill out the following blanks for the instructions of a Turing machine that accepts the language
{𝑎𝑛 𝑏𝑏 | 𝑛 ∈ 𝑁}. Use smallest possible non-negative integers to represent the states of the TM.

0 1

1 2

6. (12 points)
Fill out the following blanks for the instructions of a Turing machine that moves an input string over {a,
b} to the right one cell position. The read/write head of the control unit initially is at the left end of the
input string. The rest of the tape cells are blank. The TM will move the entire string to the right one cell
position and leave all remaining tape cells blank. The read/write head ends at the right end of the output
string.

0 2

1 2

1
2 2

2
• Solutions must be typed (word processed) and submitted both as a pdf file and a word file to Canvas before
23:59 on 11/17/2023.
• Don’t forget to name your files as
CS375_2023f_HW7_LastName.docx / CS375_2023f_HW7_LastName.pdf

You might also like