GATE | GATE CS 2013 | Question 65

What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type A -> є and A -> a) to parse a string with n tokens?
(A) n/2
(B) n-1
(C) 2n-1
(D) 2n


Answer: (B)

Explanation: Given in the question, a grammar with no epsilon- and unit-production (i.e., of type A -> є and A -> a) .

Suppose the string is abcd. ( n = 4 )

We can write the grammar which accepts this string as follows:


S->aB
B->bC
C->cd 

The Right Most Derivation for the above is:


S -> aB ( Reduction 3 )
-> abC ( Reduction 2 )
-> abcd ( Reduction 1 )

We can see here that no production is for unit or epsilon. Hence 3 reductions here.

We can get less number of reductions with some other grammar which also does’t produce unit or epsilon productions,


S->abA
A-> cd

The Right Most Derivation for the above as:


S -> abA ( Reduction 2 )
-> abcd ( Reduction 1 )

Hence 2 reductions.

But we are interested in knowing the maximum number of reductions which comes from the 1st grammar. Hence total 3 reductions as maximum, which is ( n – 1) as n = 4 here.

Thus, Option B.

Quiz of this Question




Recommended Posts:



4 Average Difficulty : 4/5.0
Based on 1 vote(s)