HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to find the pumping length of a context-free language?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thehowfreelengthlanguagepumpingfindcontext

Problem

Please help me understand, and if possible, tips, to determine a pumping length $p$.

Suppose I have the example :

Let $G$ be a Context-Free-Grammar with a set of variables $\{S,A,B,C\}$, set of terminals $\{0,1\}$, start variable $S$, and rules

$S \to ABA \mid SS$

$A \to S0 \mid 1C1$

$B \to S1 \mid 0$

$C \to 0$

Now given the above, how do I find the pumping length $p$?

Please explain how you actually got it from the grammar.

Solution

As Raphael says in the comments, any sufficiently large number is suitable as a pumping length, however (also as he points out), the proof of the pumping lemma gives an upper bound for the minimum pumping length.

Similar to the pumping lemma for regular languages, we want to take a length that is sufficiently large that we can guarantee that we have used the same production at least twice. For regular languages this often easy to think of as the number states in a minimal DFA for that language.

For context free languages expressed with a grammar, we can take a similar approach and ask "how many symbols can be in the string before I know that I must have used some production twice?". To figure this out you may want to consider how many symbols any production could insert into the string, and what the parse tree for a sufficiently long string may look like (you can consider each level of the tree to be one production). If you do this correctly you can get a minimal pumping length for that grammar (not exactly a precise concept), then taking the minimum of these minimal lengths over all grammars for the language will give you the minimum for the language.

Further hint:


If there's a rule with $m$ symbols on the right hand side, and the parse tree is $d$ levels deep, what's the maximum number of symbols in the string?

Context

StackExchange Computer Science Q#11183, answer score: 3

Revisions (0)

No revisions yet.