首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导program留学生程序、讲解Java程序设计、c++,Python编程语言调试 解析Haskell程序|讲解R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
Problem 1:
Show that the language L = {w ∈ {a, b, c}∗
: na(w) + nb(w) = nc(w)} is context-free, but not linear.
In order to show that the language is context-free, we will give the corresponding NPDA.
Define M = ({q0, q1}, Σ, {a, c, z}, δ, q0, z, {q1}) with
δ(q0, a, z) = {(q0, az)}, δ(q0, a, a) = {(q0, aa)}, δ(q0, a, c) = {(q0, λ)},
δ(q0, b, z) = {(q0, az)}, δ(q0, b, a) = {(q0, aa)}, δ(q0, b, c) = {(q0, λ)},
δ(q0, c, z) = {(q0, cz)}, δ(q0, c, a) = {(q0, λ)}, δ(q0, c, c) = {(q0, cc)},
δ(q0, λ, z) = {(q1, λ)}.
Then M accepts L since it keeps count of how many a’s and b’s are read with the stack symbol a and how many c’s
with the symbol c. For each a and b seen it will cancel a c if that is on the top of the stack or add an a. Similarly, for
each c seen, it will add a c to the stack or cancel an a if it is on top of the stack. Finally, we only accept if the number
of c’s is the same as the number of a’s and b’s combined, that is they all cancel each other on the stack.
To show that the language is not linear, we will use the pumping lemma for linear language. Assume that the
language is linear and apply the PL to the string w = amc
2mb
m.
|uvyz| ≤ m shows that in this case the strings u, v must both consist entirely of a’s, that is v = ak1 and y, z must both
consist entirely of b’s, that is y = bk2. If we pump this string once, we get am+k1
c
2mb
m+k2
, with either k1 ≥ 1 or k2 ≥ 1, a
result that is not in L. This is a contradiction, it proves that the language is not linear.
Problem 2:
Show that the family of context-free languages is not closed under difference in general, but is closed under regular
difference, that is, if L1 is context-free and L2 is regular, then L1 − L2 is context-free.
To show that context free languages are not closed under difference in general, we will give two context free
languages whose difference is no longer context free. Let L1 = {an b
n
c
m |m, n ≥ 0} and L2 = {𝑎𝑚𝑏
𝑛𝑐 ̅̅̅̅̅̅̅̅̅̅𝑛̅ | m, n ≥ 0}. L1
and L2 are both context free languages (in fact deterministic context free languages),
which is not context free as stated in class. Thus, the family of context free languages is not closed under
difference.
Next, we will show that the class of context free languages is closed under regular difference. Let L1 be any context
free language and L2 be any regular language. We know that regular languages are closed under complement,
therefore L2 is a regular language. We also know that context free languages are closed under regular intersection.
Thus, L = L1 − L2 = L1 ∩ 𝐿2
̅̅̅ is a result of a regular intersection and is therefore a context free language.
Problem 3:
Design Turing machines to compute the function for x and y positive integers represented in unary. For each of
these problems let u(x) = 1x where 1x
is 1 concatenated with itself x times.
We will assume that u(0) = λ and will be represented by the tape having only blanks on it.
(a) 𝑓(𝑥) = 3 𝑥.
The input to our tape will be u(x) and the output will be u(3x). We will first mark all the 1’s and then for
every marked 1 we see we will write two 1’s at the end of the string, thus tripling the string. We will define
the TM as follows:
States Q = {q0, q1, q2, q3, qf}, where q0 is the start state and qf the only final state,
The input to our tape will be u(x) − u(y) and the output will be u(x − y) if x > y and the blank tape otherwise.
One strategy will be to remove a 1 from the end of the string (the y portion) and then remove a
corresponding 1 from the front of the string (the x portion). We continue until either we are out of 1’s in
the y portion, in which case we have u(x − y) on the tape, or we are out of 1’s in the x portion in which case
x ≤ y, so we clear the tape and halt with the blank tape.
c) 𝑓(𝑥, 𝑦) = 2𝑥 + 3𝑦
The input to the tape will be u(x) + u(y) and the output will be u(2x + 3y). We will first mark all the 1’s
before the plus with one dot and then change the plus to a one with two dots and continue marking every
one after it with two dots. We will remove the last 1 as extra to the sum. Then for every 1 with two dots
seen we will write two 1’s and the end of the string and for every 1 with one dot we will write one 1 and
the end of the string, yielding the required total.
The input to the tape will be u(x) and the output will be u( ⌈𝑥2⌉ ). Our strategy is to mark a 1 at the start of
the string and remove a corresponding one at the end of the string. We will repeat marking the next
unmarked 1 at the beginning and removing another 1 at the end. We will continue until there is no
unmarked 1 left (x was even) and we cut the output in half, or there is no one left to remove at the end (x
was odd) and the output is the fraction rounded up. Then we clear all marks and halt.
e) 𝑓(𝑥) = 𝑥 𝑚𝑜𝑑 5
The input to the tape will be u(x) and the output will be u(x mod 5). Our strategy is to mark all the 1’s as we
scan to the right using our states to remember how many 1’s we have seen mod 5. Then we will remove
the marks from that many 1’s and scan back to the left over the remaining marked 1’s. Then we will delete
all the marked ones and halt with x mod 5 on the tape.
Problem 4:
Let L be a deterministic context-free language and define a new language L1 = {w| aw ∈ L, a ∈ Σ}. Is it necessarily
true that L1 is a deterministic context free language?
No! Let’s give a counter-example. Let L = {c an b
n
| n ≥ 0} ∪ {d an b 2n | n ≥ 0}, then L is a deterministic context free
language, if we start with a c we follow a branch where we accept or if we read an a we push one extra a on the
stack and then pop one a for each b read, accepting only if the stack is empty. If we start with a d, then we follow
another branch where we accept or if we read an a we push two extra a’s on the stack and then for each b rea d we
pop one a, accepting only if the stack is empty. In every configuration we can only move to one other configuration,
meeting the criteria for determinism. However, then L1 = {an b
n
| n ≥ 0} ∪ {a
n b
2n | n ≥ 0} (removing the first symbol
from every string in L), which is the language in Example 7.11 (Peter Liz 3rd ed.) which was shown in the example to
be nondeterministic.
Problem 5:
Transform the grammar with productions S → abAB, A → baB|λ, B → BAa|A|λ. into Chomsky normal form.
Removing λ−productions:
Here A and B are nullable variables, we get
S → abAB|abA|abB|ab, A → baB|ba, B → BAa|A|Ba|Aa|a.
Removing unit-productions:
S → abAB|abA|abB|ab, A → baB|ba, B → BAa|baB|ba|Ba|Aa|a.
There are no useless productions in the grammar.
Now, we introduce variables C and D to substitute terminals a and b.
S → CDAB|CDA|CDB|CD, A → DCB|DC,
B → BAC|DCB|DC|BC|AC|a, C → a, D → b.
Finally, we introduce variables to shorten the right sides of the production.
S → EF|EA|EB|CD A → GB|DC, B → BH|GB|DC|BC|AC|a,
E → CD, F → AB, G → DC, H → AC, C → a, D → b.
Problem 6:
Construct an NPDA corresponding to the grammar S → aABB|aAA, A → aBB|a, B → bBB|A.
The grammar does not have any λ−productions. So, we can convert it into Greibach normal form. Get rid of the unit
production,
S → aABB|aAA, A → aBB|a, B → bBB|aBB|a.
Define M = ({q0, q1, qf }, Σ, {S, A, B, z}, δ, q0, z, {qf }) with
δ(q0, λ, z) = {(q1, Sz)}, δ(q1, a, S) = {(q1, ABB),(q1, AA)},
δ(q1, a, A) = {(q1, BB),(q1, λ)}, δ(q1, b, B) = {(q1, BB)},
δ(q1, a, B) = {(q1, BB),(q1, λ)}, δ(q1, λ, z) = {(qf , z)}
Problem 7:
Is it possible for a regular grammar to be ambiguous?
Yes. Consider the grammar
S → A|λ A → λ.
Then there are two leftmost derivations that generate the string λ. The first is S ⇒ λ and the second is S ⇒ A ⇒ λ.
Thus, this regular grammar is ambiguous. Regular grammars cannot be inherently ambiguous.
Problem 8:
Eliminate useless productions from S → a|aA|B|C, A → aB|λ, B → Aa, C → cCD, D → ddd.
Following the algorithm given in the proof of Theorem 6.2 (3rd edition), we will first remove productions that
cannot generate any strings. Let V1 = ∅. Since S → a, A → λ and D → ddd are productions we add S, A and D to V1.
Then, since B → Aa is a production we add B to V1. There are no more variables that can produce a string following
the algorithm. Removing these useless productions yields the grammar
S → a|aA|B, A → aB|λ, B → Aa, D → ddd.
Next, we remove the unreachable variables. We will start with V2 = {S} since S is the start variable, we always reach
it. We can reach the variables A and B from S so they are added to V2. A and B can only reach each other so our
algorithm terminates. Since D is not in V2 it cannot be reached by any derivation of this grammar. Therefore, we
remove all productions with D, yielding the final grammar free of useless productions and useless variables.
S → a|aA|B, A → aB|λ, B → Aa,
Problem 8:
Construct NPDA that accept the following language on Σ = {a, b, c}. (a) L = {an b
2n | n ≥ 0}.
Define M = ({q0, q1, q2, q3}, Σ, {a, z}, δ, q0, z, {q0, q3})
with δ(q0, a, z) = {(q1, aaz)}, δ(q1, a, a) = {(q1, aaa)},
δ(q1, b, a) = {(q2, λ)}, δ(q2, b, a) = {(q2, λ)}, δ(q2, λ, z) = {(q3, λ)}.
Then M accepts L since it accepts the empty string and for each a seen it pushes two additional a’s onto the stack (3
total). Then it pops one a for each b seen guaranteeing there are twice as many b’s as a’s. Finally, it accepts if the
input is done and there are no more a’s on the stack.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!