The data structure required to check whether an expression contains a balanced parenthesis is?
Options
- A. Array
- B. Queue
- C. Stack
- D. Tree
C. Stack
To check balanced parentheses in an expression:
Push every opening bracket ({[ into the stack
When a closing bracket )}] appears → pop from stack
If brackets match correctly and stack is empty at the end → expression is balanced
This works because Stack follows LIFO (Last In, First Out) principle, which perfectly handles nested structures.
Attempt Quiz Now:
BPSC Tre 4.0 DSA Practice Set