Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE CS 1997 | Question 55

  • Difficulty Level : Basic
  • Last Updated : 07 Oct, 2020

Consider the grammar

S→ bSe
S→ PQR
P→ bPc
P→ ε
Q→ cQd
Q→ ε
R→ dRe
R→ ε

where S,P,Q,R are non-terminal symbols with S being the start symbol; b,c,d,e are terminal symbols and ‘ε’ is the empty string. This grammar generates strings of the form bi, cj, dk, em for some i, j, k, m ≥ 0.

  • (a). What is the condition on the values of i, j, k, m ?
  • (b). Find the smallest string that has two parse trees.


Answer:

Explanation: (a). Condition on the values of i, j, k, m

i+k = j+m 

where i, j, k, m >= 0

(b). Smallest string that has two parse trees = bcde
Production used to generate the smallest string is :-

S- > bSe
S- > bSe
S- > bSe
S -> PQR
P-> null
Q ->cQd
Q -> null
R- > null 

Finally you will get the string like ” bbbcdeee”
which means that i=3, j=1, k=1, m=3 and hence the answer i+k=j+m .

Now production used to generate the smallest string is :-

S-> bSe 
S ->  bPQRe
S ->  bεQRe
S ->  bcQdRe
S ->  bcεdRe
S ->  bcdεe
S -> bcde 

Hence smallest string is bcde.
Therefore we can see same number of b, c, d, e is generated.
Power of b, c, d, e are respectively i, j, k, m.
Hence relation between i, j, k, m is :-

i+k = j+m   


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!