The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
2.7k 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.7k points) | 2.7k views

5 Answers

+22 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.4k points)
edited by
+4 votes

this might Help you

answered by (369 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 (7.3k 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.6k points)
Answer:

Related questions



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

44,150 questions
49,639 answers
163,323 comments
65,808 users