write a java program using stacks: 1. For a given expression in the form of a string, find if there exist any redundant brackets or not. It is given that the expression contains only rounded brackets...


write a java program using stacks:


 1.     For a given expression in the form of a string, find if there exist any redundant brackets or not. It is given that the expression contains only rounded brackets or parenthesis and the input expression will always be balanced. A pair of the brackets is said to be redundant when a sub-expression is surrounded by unnecessary or needless brackets.



            Sample Input 1:


            (a+b)+c



            Sample Output 1:


            false



Explanation:


Since there are no needless brackets, hence, the output must be 'false'.



            Sample Input 2:


((a+b))



            Sample Output 2:


            true



            Explanation”


The expression can be reduced to (a+b). Hence the expression has redundant brackets and the output will be 'true'.



Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here