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
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
Copyright © 2021 Jogjafile Inc.
The shortest string in
Lis the empty string,e. Given a stringsin the language, the following rules hold:asis inLasbis inLasbbis inLWe can combine these observations to get a context-free grammar:
By our observations, every string generated by this grammar must be in
L. To show that this is a grammar forL, we must show that any string inLcan be generated. To get a stringa^n b^kwe can do the following:xtimesytimesztimesx + y + z = ny + 2z = kSetting
y = k - 2zand substituting we findx + k - 2z + z = n. Rearranging:k > n, thenzandxcan be chosen however desired so long ask - n = z - x.k < n, thenzandxcan be chosen however desired so long asn - k = x - z.k = n, observe we might as well just choosey = n.Note that we can always choose
zandxin our above example since0 <= x, z <= nand0 <= k <= 2n.