The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
2.5k views

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

  1. queue
  2. stack
  3. tree
  4. list
asked in DS by Veteran (59.5k points) | 2.5k views

5 Answers

+21 votes
Best answer
STACK scan the expression from left to right whenever a left paranthesis is encountered just PUSH it into stack and whenever a right paranthesis is encountered just POP it from stack. If at the end of expression we are left with an empty stack then it is a correctly parenthesized expression.
answered by Boss (14.2k points)
edited by
+4 votes

this might Help you

answered by (367 points)
0
why tree and list will not best?

 

just was knowledge can u explain @BHAVESH
0
how can we use tree to check balanced paranthesis?? sombody please share.
+3 votes
Example of Stack

7  -  (   (  x  *  (  (  x  +  y  )  / (  j  -  3   )  )  +  y   )  /  (  4  -  2.5  )  )
0 0  1  2 2 2  3 4 4  4  4 3 3 4 4 4 4  3  2 2  2  1 1  2 2  2   2  1 0

Eventually we get 0 in stack
answered by Loyal (6.6k points)
+3 votes
correct answer should be Stack. to evaluate arthimatic expression we use stack data structure.
answered by (41 points)
+3 votes
Stack
answered by Loyal (7.2k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

38,112 questions
45,620 answers
132,318 comments
49,300 users