The Definition
Brackets are only useful if they enclose an operator. For example `(a+b)` encloses `+`. `(a)` encloses no operators, making it mathematically useless (redundant).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Given a mathematical expression, determine if it contains any redundant brackets. `(a+b)` is useful, but `((a+b))` contains a redundant outer shell.
Brackets are only useful if they enclose an operator. For example `(a+b)` encloses `+`. `(a)` encloses no operators, making it mathematically useless (redundant).
Push everything (open brackets, operators, operands) onto a stack EXCEPT closing brackets. When you see a closing bracket, start popping.
Pop until you hit the matching open bracket. If you didn't pop any operators (`+`, `-`, `*`, `/`) during that process, the brackets were redundant!