retagged by
1,258 views

1 Answer

0 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
Position:
Show:

Related questions

1 1 vote
0 0 answers
234
234 views
amanbadone0 asked Nov 12, 2025
234 views
Self DoubtSuppose there are about n tokens in a input string , each of the token is matched with some production rule, how many total production rules used in the parse t...
0 0 votes
3 3 answers
2.5k
2.5k views
Yogendraa asked Jun 9, 2022
2,541 views
E E+EE E*EE idInput string: id + id + id
0 0 votes
1 1 answer
460
460 views
saumya mishra asked Jun 11, 2018
460 views
How to make a parse tree for the expression$a+b*c/b*c*f?$
1 1 vote
1 answers 1 answer
1.0k
1.0k views
learner_geek asked Aug 2, 2017
1,020 views
If i am wrong please let me correct with giving proper explanation.