What does the following context-free grammar describe?
S is the start symbol and the set of nonterminal symbols is . Here are the production rules:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The correct answer is "strings that end in 0" The easiest way to figure this out is the provide examples of strings that can be made with these rules that eliminate some of the choices.
I’ll build up a string as I go through the rules: string = “”
S --> 0 (string = “0”)
S --> 0S (string = “00”)
S --> 1S (string = “100”)
S --> 1S (string = “1100”)
This string has an even (and equal) number of 1’s and 0’s so “strings that have an even number of 1’s and 0’s” and “ strings that have an equal number of 1’s and 0’s ” are eliminated.
Resetting the string to “”
S --> 0 (string = “0”)
S --> 1S (string = “10”)
This has an odd number of 1’s, so “strings that have an odd number of 1’s” is eliminated.
Now we are left with “strings that end in 1” and “strings that end in 0”
Is it possible to make a string that ends in a 1? No, because the start symbol must be 0 first. Any string that we make, in fact, will end in a 0 because we only ever add symbols to the left of the existing string. If the first symbol is always 0, then it doesn’t matter what we add to the left, the rightmost element (the end) will always be 0.