Title: Key to Homework
1Key to Homework 2
- 1. What is the language of L-system G (a, b,
c, h, acb ), where the rewriting rule h is
defined as follows - h (a) aa
h (b) cb h (c) a - Answer Applying h iteratively on acb, we get
the following acb ?? aaacb ?? aaaaaaacb ??
aaaaaaaaaaaaaaacb ?? . . . - The number of as increases with the following
pattern 1, 21, 421, 8421, . . . , and so
on. If we apply h i times, we get - string a1a2a4. . . .aicb. Since 1248 . . .
2i 2i1 1, we can express the language of
the L-system as follows. - arcd r 2i1 1, i ? 0
2. Construct a syntax diagram which defines the
language of the following context-free grammar.
S ? aSbB A
A ? bSa ba ab B ? bB ?
Answer
S
B
24. Suppose that in the Pascal Syntax Flow Graph
(see your handout) digit are defined as the
following syntax flow graphs. Write a
context-free grammar that generates all unsigned
numbers defined by the Pascal syntax flow graph
unsigned number in the handout.
Let lt . . .gt denote nonterminals, and
ltunsigned numbergt be the start symbol of the
grammar.
ltunsigned numbergt ? ltunsigned integergt
.ltunsigned integergt e ltsigngt ltunsigned integergt
ltunsigned integergt .ltunsigned integergt
ltunsigned integergt e ltsigngt ltunsigned integergt
ltunsigned integergt ltunsigned integergt ?
ltdigitgt ltunsigned integergt ltdigitgt
ltdigitgt ? 1 2 ltsigngt ? - ?
33. What does the following Turing Machine (TM)
do? Explain in detail referring to the states.
Assume that the input is a string in 0, 1 .
(Hint Trace the machine operation with a simple
example.)
Answer
- Given a binary number on the tape, the Turing
machine increments and shifts - it as follows
- In state 0, the head move all the way to the
right until it the blank next to the last symbol,
and back up one cell to the left and enters state
1. - Moving to the left changes all 1s to 0, until it
reads 0. The machine changes this 0 to 1, enters
state 2 and moves all the way to the right until
it hits a blank, and then back up in state 3. -
- Above procedures (1) and (2) increment the binary
number on the tape by one. (There is an
exceptional case if the number is all 1s, the
increment will be stuck at state 1, and will not
work.) - (3) If the machine reads symbol 0 (symbol
1), it replaces the symbol with blank and moves
to the left entering state 4 (respectively, state
5). - (4) Changing states between 4 and 5, the
machine shifts the binary string to the left by
one cell.
45. Construct a TM which, given a string x ? a,
b, rearrange the symbols in x such that all
as come fist then bs follow. For example, if
the input is abbaaba, then the result will be
aaaabbb. When the work is complete the TM should
be in an accepting state and the tape should only
contain rearranged string. For your answer, you
should first informally explain your idea in
detail and then show the transition graph of the
TM.
An idea Shifting the input string to the right,
if there is a symbol b before an a, stop shifting
and move that b to the end of the string. This
operation repeats until it sees no b to the left
of an a.(See the illustration in Figure (a).) In
Figure (b), the machine enters in state 3 if it
sees an a after reading bs.
(B, a, N)
Figure (a). Shifting the string and transposing
bs.
Figure (b). State transition graph