1.

The data structure required to check whether an expression contains a balanced parenthesis is?(a) Stack(b) Queue(c) Array(d) TreeThis intriguing question comes from Stack Operations in portion Abstract Data Types of Data Structures & Algorithms IThis question was addressed to me in class test.

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.


Discussion

No Comment Found

Related InterviewSolutions