The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
37 views
Consider the following CFG.
S → aSa | bSb | a | b | ε
For the above CFG, the total number of strings generated whose length is less than or equal to 8 [exclude the empty string] is _____________.
asked in Theory of Computation by Active (2.8k points) | 37 views
0
Is the answer 60?

2 Answers

+4 votes
You could do it this way:

The number of length one strings (L1) = 2.
The number of length two strings (L2) = 2.

These can be trivially found out.

Now for L3, we fix the first and last positions as a_a or b_b. Now, in the blank there has to be a string of length 1, for which we have two options. Therefore, the total number of strings are (a_a)*2 + (b_b)*2 = 4.

We can extend this logic for all the further substrings.

L4 = a__a + b__b where the blank will contain strings of length 2.
L5 =  a___a + b___b where the blank will contain strings of length 3.
L6 = a____a + b____b where the blank will contain strings of length 4 and so on.

When you add all these, you should get 60.
answered by Loyal (5.9k points)
0

Good derivation bro....

To make it complete add that

(n) = T(2)*T(n-2) for n>2

+3 votes

Given grammar is produce palindrome of string.

 

 

answered by Boss (24.3k points)

Related questions

0 votes
1 answer
2
asked Dec 6, 2016 in DS by Vishal Goyal Active (1.9k points) | 77 views


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,237 questions
49,719 answers
163,886 comments
65,834 users