Scan the string from left to right: 1. Whenever an opening bracket is encountered, push it onto the stack.
2. Whenever a closing bracket(parenthesis / curly brace) is encountered, pop one bracket from the stack and compare it with the encountered closing bracket.
2.a. If the two brackets are not of the same type, the expression is not balanced.
2.b. If the two brackets are of the same type, continue scanning.
3. At the end of the scan, the stack should be empty. Otherwise, it's an unbalanced expression.