Question

In: Computer Science

Let G be any context-free grammar. Show that the number of strings that have a derivation...

Let G be any context-free grammar. Show that the number of strings that have a derivation in G of length n or less, for any n > 0, is finite.

Could you please answer with clear explanation. The question is from Elaine Rich's Automata, Computability and Complexity Chapter 11 Exercise 14.

Solutions

Expert Solution

Question: Let be any context-free grammar. Show that the number of strings that have a derivation in G of length n or less, for any n > 0, is finite.

Sol: Define ()to be the set of strings in () that have a derivation in of length n or less. We can give a (weak) upper bound on the number of strings in ().

Let be the number of rules in and let be the largest
number of nonterminals on the right hand side of any rule in .

For the first derivation step, we start with and
have choices of derivations to take. So at most strings can be generated. (Generally there will be many fewer, since many rules may not apply, but we're only producing an upper bound here, so that's okay.)

At the second step, we may have strings to begin with (any one of the ones produced in the first step), each of them may have up to nonterminals that we could choose to expand, and each nonterminal could potentially be
expanded in ways.

So the number of strings that can be produced is no more than . Note that many of them aren’t strings in since they may still contain nonterminals, but this number is an upper bound on the number of strings in that can be produced.

At the third derivation step, each of those strings may again have nonterminals that can be expanded and ways to expand each. In general, an upper bound on the number of strings produced after derivation steps is , which is clearly finite.

The key here is that there is a finite number of rules and that each rule produces a string of finite length.


Related Solutions

Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal...
Let G = (AN , AT , S, P) be a context-free grammar in Chomsky normal form. Prove that if there exists a word w ∈ L(G) generated by a derivation that uses more than |P| + |AT | steps, then L(G) is infinite.
Prove that if G is a context-free grammar in which every variable occurs on the left...
Prove that if G is a context-free grammar in which every variable occurs on the left side of at most one production, then G is unambiguous.
Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = {...
Consider the context-free grammar G = ( {S}, {a, b}, S, P) where P = { S -> aaSb | aab }. Construct a NPDA M that such that L(M) = L(G). I would like the transition graph for this NPDA please.
What makes a deterministic context free grammar deterministic?
What makes a deterministic context free grammar deterministic?
Theory of Computation Problem Let G be an arbitrary CFG (Context-free Grammer), and let DG be...
Theory of Computation Problem Let G be an arbitrary CFG (Context-free Grammer), and let DG be the string-pushing PDA(pushdown automata) for it. Let w be some string of length n in L(G). Suppose you know that the leftmost derivation of w in G consists of m substitutions. How many transitions would be in the corresponding computation of DG for input string w? Justify your answer carefully.
Consider the following context-free grammar G: E ® T + E ® * T i E...
Consider the following context-free grammar G: E ® T + E ® * T i E ® f i E ® * f + T ® + Questions: (5 points) Compute the Canonical LR(1) Closure set for state I0 for grammar G. (10 points) Compute (draw) the DFA that recognizes the Canonical LR(1) sets of items for grammar G. (5 points) Construct the corresponding Canonical LR(1) parsing table. (10 points) Compute (draw) the DFA for LALR(1). (5 points) Construct LALR(1)...
Give a context-free grammar for {w ∈ {b, c}∗| #c(w) = #b(w)}.
Give a context-free grammar for {w ∈ {b, c}∗| #c(w) = #b(w)}.
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free...
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free Languages are Closed under union(∪), concatenation(·), kleene star(*). (Hint: If L1 and L2 are Context Free languages then write Context Free grammar equivalent to L1 ∪ L2, L1 · L2, L∗ 1 ) 2. Show that if L1 and L2 are Context Free Languages, then L1 ∩ L2 is not necessarily Context Free. (Hint: Use Proof by Counter Example)
Show that for any square-free integer n > 1, √ n is an irrational number
Show that for any square-free integer n > 1, √ n is an irrational number
(a) Let G and G′ be finite groups whose orders have no common factors. Show that...
(a) Let G and G′ be finite groups whose orders have no common factors. Show that the only homomorphism φ:G→G′ is the trivial one. (b) Give an example of a nontrivial homomorphism φ for the given groups, if an example exists. If no such homomorphism exists, explain why. i.φ: Z16→Z7 ii.φ: S4→S5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT