Which of the following data structures can be used for parentheses matching?
Options
- A. priority queue
- B. queue
- C. n-ary tree
- D. stack
D. stack
Parentheses matching requires:
Checking opening brackets: ({[
Matching them with corresponding closing brackets: )}]
A Stack follows LIFO (Last In, First Out) principle:
Push opening bracket onto stack
When closing bracket appears → pop from stack
Check if it matches
If stack is empty at end → parentheses are balanced
Attempt Quiz Now:
BPSC Tre 4.0 DSA Practice Set