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 \rightarrow \epsilon$ and $A \rightarrow a$) to parse a string with $n$ tokens?

Here, in this question we are not supposed to have A -> a, even though that is not a unit production. Obviously a mistake in question, but we must follow what is written in question. Answer to this question is n-1, as given by GATE key. So, if similar thing happens in GATE, follow the question word by word and never try to correct the question.

Since it is not in CNF we can't take A->a but we can take A->aa i.e. two terminals. We could have taken three, four anything but to get the highest no. of reductions we consider two as one is not allowed.

Also to increase the number of reductions the productions should be in the form of X->YZ i.e. two non terminals reduced to 1.

Why don't we take X->Y form? I feel that if this was allowed then no. of reductions could have not been derived because lets say our productions are S->A, A->B, B->C, C->c. So no. of reductions needed to reduce "c" to S is c->C-; C->B; B->A; A->S is 4. Now to get highest no. of reductions we can just keep on increasing this unit productions as much as we can i.e. S->A, A->B, B->C, C->D, D->E; E->c. So now to reduce c we take 6 reductions. So these unit productions cannot be considered here in our question. Hence we take X->YZ form.

Comparing it with the CNF's formula:

What we did in case of CNF: If "n" is the length of string, each character of the string can be reduced to onenon terminal. So no. of non terminals obtained in the 1st reduction (in bottom up manner is "n" since one terminal reduced to exactly one non terminal) is "n".

Now these "n" non terminals form the leaf nodes of a binary tree. Such binary tree(where every non-leaf node has 2 children i.e. productions are in the form of X->YZ) with n leaf nodes takes (2n-1) moves to reduce to the start symbol.

Now suppose to derive a string of length $n$, $n-1$ steps are needed to get all non-terminals.Further, n steps would be required to expand each non-terminal to a terminal accounting to a total of $2n-1$ steps to derive a string of length $n$

But hold.Here we would get a string of length $2n$, so to derive a string of length $2n$, we made $2n-1$ steps.

Let $2n=k$, then to derive a string of length $k$, maximum steps we need is $k-1$

here i m taken each possible case. case1-> A->epsilon(Null prod) and A-> B (Unit prod.) not allowed then for 'n' length token how many maximum reduce move required . lets take example - for string 'ab' S->AB : A->a , B->b then here required 3 reduced moves . lets take other string ex- abc for that i do S->AB , A->DE , D->a , E->b ,B->c so it is 5 so we can say in general answer will be 2n-1

case 2 . if A-> epsilon(Null prod) and A-> a are not allowed but unit production allowed then for that if i take string 'ab' then for that S->A , A->B, C->D, D->E and so on ..at last producion i write like as K->ab so here for that we can't write a general form .

case3. if A-> epsilon(Null prod) and A-> a are not allowed and also unit production not allowed then take string 'ab' for that you can write only S->ab for that required 1 reduce and for string 'abcd' we can write S->AB , A->ab ,C->cd so required 3 so in general required 'n-1' reduce . then according to arjun sir no need to be change the question so i m going wid "n-1"

@vaishali here they are not mention wheather we follow CNF or not just simply think that maximum how many step can we take to genearte a string without using any production A->a and unit production(A->B) and null production

Your identity must be verified before you can post a comment. Please wait if already uploaded identity proof or upload your proof here

0 votes

Whatever you have learnt is Right, the problem is in the question itself-

This question has Typing mistake because Unit production means A->B where A&B both are non-terminal and here a should have been B.

so they did mistake and to make it right they answered on the basis of this question, that answer would be n-1. but to make it max. no of reduction you can take A->B, B->C, C->D.......which is correct so marks should have been given to all.

however according to standard epsilon & unit production removal the string can be generated in min. n-1 and max. 2n-1 reductions.

Your identity must be verified before you can post a comment. Please wait if already uploaded identity proof or upload your proof here

0 votes

Since what can we conclude from this question is to make parse tree we are not going to use any any null and ONE length production .

Think like this we are trying to make the binary tree and there in not any single child internal node and 0 child .

0 child(leaf or symbol ) is only allowed at the bottom level . So now we have n leaf so to maximize the internal node(which is nothing but a reduction like A=ab) we will use only those production (NOTE THAT NO INFO GIVEN ABOUT GRAMMAR SO YOUR CHOICE TO CHOOSE ANY GRAMMER )which will reduce two symbol to One (like S=AB) in such way we know that for a perfect binary tree if we have n leaf node then (n -1) internal node which is nothing but no of reduction so