@Amit: There is more to it than that, involving operators of equal
precedence. Consider a-(b+c) versus (a-b)+c or a+(b-c), or a/(b*c)
versus (a/b)*c or (a*b)/c. In the first case of each set, removing the
parentheses is wrong, but in the other cases of each, the parentheses
are redundant and can be removed. I don't think this can be solved by
choosing different precedences for + and - or for * and / because
there is the left-to-right rule for applying sequences of + or -
operators or sequences of * and / operators.

Dave

On Oct 8, 2:46 am, Amit Agarwal <lifea...@gmail.com> wrote:
> 1) Recursion has to be used.
> 2) Stack has to used
> 3) If any pair of paranthesis doesn't has any operator outside it, remove
> the pair
> 4) If low precedence operator is inside the pair of paranthesis than the one
> surrounding the pair of parenthesis, don't remove paranthesis.
> 5) If high precedence operator is inside the pair of paranthesis than the
> one surrounding the pair of parenthesis, remove paranthesis.
>
> -Regards
> Amit Agarwal
> blog.amitagrwal.com
>
>
>
> On Fri, Oct 8, 2010 at 11:42 AM, snehal jain <learner....@gmail.com> wrote:
> > write a program to remove redundantt parenthesis from an expression
> > eg
> > input ((a+b))
>
> > output  a+b
>
> > input   a+(b*c)
>
> > output  a+b*c
>
> > input    a*(b+c)
> > output   a*(b+c)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to