Reputation: 59
L = {a^n b^k | 2n >= k}
For example.: abb is element of L, aabbb is element of L, ε is element of L, but babbb is not element of L, abbb is not element of L
Upvotes: 0
Views: 173
Reputation: 28322
The shortest string in L
is the empty string, e
. Given a string s
in the language, the following rules hold:
as
is in L
asb
is in L
asbb
is in L
We can combine these observations to get a context-free grammar:
S := aSbb | aSb | aS | e
By our observations, every string generated by this grammar must be in L
. To show that this is a grammar for L
, we must show that any string in L
can be generated. To get a string a^n b^k
we can do the following:
x
timesy
timesz
timesx + y + z = n
y + 2z = k
Setting y = k - 2z
and substituting we find x + k - 2z + z = n
. Rearranging:
k > n
, then z
and x
can be chosen however desired so long as k - n = z - x
.k < n
, then z
and x
can be chosen however desired so long as n - k = x - z
.k = n
, observe we might as well just choose y = n
.Note that we can always choose z
and x
in our above example since 0 <= x, z <= n
and 0 <= k <= 2n
.
Upvotes: 0