retagged by
787 views
0 votes
0 votes
Consider the following grammar

$S \rightarrow SS/Sa/aS/a$

Construct Parse Tree for $w=aaaa$ as many as possible? How many parse trees are possible?
retagged by

1 Answer

0 votes
0 votes

Let f(n) be the number of ways to generate an. We have,

f(n) = $2*f(n-1)$  <-- due to the rule  S -> aS|Sa
       + $\sum_{i=1}^{n-1} f(i)*f(n-i)$ < --- due to the rule S -> SS

So, $f(n) = 2f(n-1)+\sum_{k=1}^{n-1} f(k)*f(n-k)$ with f(1) = 1

$\therefore f(2)=2f(1)+f(1)^2 = 3 \\ f(3) = 2f(2)+f(1)*f(2)+f(2)*f(1) = 12 \\ f(4) = 2f(3)+f(1)*f(3)+f(2)^2+f(3)*f(1) = 57$

edited by

Related questions

0 votes
0 votes
3 answers
1
0 votes
0 votes
1 answer
2
saumya mishra asked Jun 11, 2018
225 views
How to make a parse tree for the expression$a+b*c/b*c*f?$
1 votes
1 votes
1 answer
3
learner_geek asked Aug 2, 2017
562 views
If i am wrong please let me correct with giving proper explanation.
2 votes
2 votes
1 answer
4