Reputation: 1270
I need some help with deciding if a given language is regular, context-free or not context-free. A brief, informal explanation is sufficient in the answer, hence no need to use pumping lemma.
Lets say I have the following lanugages:
L1 = { w ∈ {a, b, c, d}* | #a(w) is even, #b(w) = 1 mod 3, w does not have
a substring abc }
L2 = { w ∈ {a, b, c, d}* | #a(w) is even, #b(w) < #c(w) }
L3 = { w ∈ {a, b, c, d}* | #a(w) < #b(w) < #c(w) }
This is my solution:
L1 = L2 ∩ L3 ∩ L4 where
L2 = #a(w) is even
L3 = #b(w) = 1 mod 3
L4 = w does not have a substring abc
A DFA can be constructed for L2, becuse L2 does not need infinite memory, so L2 is regular. For L3 the same reasoning as above. And for L4 we can construct a DFA that simply does not accept "abc", hence regular.
L1 is regular because regular languages are closed under ∩ .
For L2 we can divide the language into:
L2 = L3 ∩ L4 where
L3 = #a(w) is even
L4 = #b(w) < #c(w)
We know that a DFA can be constructed for L3, hence L3 is regular. L4 is context-free because we can construct a PDA where a stack is used to count the number of a:s and b:s.
L2 is hence context-free because the ∩ of a regular language and a context-free language result in a context-free language.
For L3 we can see that it's non context-free because we are limitied to 1 stack, and to do more than 1 comparison we need more stacks.
Is my reasonings rights ? I have a exam soon and need to know if I have got the idea behind this.
Thanks in advance
Upvotes: 4
Views: 2702
Reputation: 28292
Yes, you are correct on all three counts. L1 is regular, L2 is context-free, and L3 is not context-free. You correctly apply closure properties for L1 and L2, and your reasoning is more or less correct for the last one. For the last one, I would caution you against using that rule... since there may be more than one way to think about how a language could be recognized, some of which require more than a stack, and some of which don't. Take, for instance, the non-context-free language L = {a^n b^n c^n}. The complement of this language is context-free, although sloppy application of the rule you use might lead you to believe otherwise (until you'd properly considered the matter).
Upvotes: 3