[algogeeks] Re: Remove Extra Parenthesis

2010-07-12 Thread Gene
On Jul 11, 9:58 am, amit wrote: > Give a algorithm to remove extra pair of parenthesis > Remove unnecessary from an expression : > 1) (((a))) => a > 2) (a+b) => a+b > 3) (a+b)*c => (a+b)*c > 4)(((a+b)*(c+d))+e) => (a+b)*(c+d)+e We can build an abstract syntax tree with a simple parser and then wa

[algogeeks] Re: Remove Extra Parenthesis

2010-07-11 Thread Tech Id
Assuming we do not want to remove brackets from cases like (a+b)+c, (because strictly speaking, the brackets here are not required), one algorithm to remove brackets for given above cases can be: 1) Scan through the string. 2) Increment a counter when '(' is encountered and decrement it on ')' 3)