Open In App

GATE | GATE CS 2013 | Question 65

Like Article
Like
Save
Share
Report

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). 

To get maximum number of Reduce moves, we should make sure than in each sentential form only one terminal is reduced. Since there is no unit production, so last 2 tokens will take only 1 move. 

So To Reduce input string of n tokens, first Reduce n-2 tokens using n-2 reduce moves and then Reduce last 2 tokens using production which has . So total of n-2+1 = n-1 Reduce moves. 

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 doesn’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 is maximum, which is ( n – 1) as n = 4 here. 

Thus, Option B. 


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 10 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads