+1 vote
in Data Structures & Algorithms I by (110k points)
The data structure required to check whether an expression contains a balanced parenthesis is?

(a) Stack

(b) Queue

(c) Array

(d) Tree

This intriguing question comes from Stack Operations in portion Abstract Data Types of Data Structures & Algorithms I

This question was addressed to me in class test.

1 Answer

+1 vote
by (412k points)
selected by
Best answer
Right option is (a) Stack

Explanation: The stack is a simple data structure in which elements are added and removed based on the LIFO principle. Open parenthesis is pushed into the stack and a closed parenthesis pops out elements till the top element of the stack is its corresponding open parenthesis. If the stack is empty, parenthesis is balanced otherwise it is unbalanced.

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.