Multiple choice

The best data structure to check whether an arithmetic expression has balanced parenthesis is a

  1. queue

  2. stack

  3. tree

  4. list

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Balanced parenthesis in an equation is such that the no. of opening and closing parenthesis and in correct order should be there. We can check balancing using stack. When we get any opening parenthesis then we push that in the stack & if we get a closing one then we pop the stack. After the complete scanning of input string if stack is found empty then the arithmetic expression is balanced