27 27 votes The best data structure to check whether an arithmetic expression has balanced parentheses is a queue stack tree list Data Structures gatecse-2004 data-structures easy stack + – Kathleen 11.1k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 44 44 votes 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. Bhagirathi answered Sep 25, 2014 • edited Jun 14, 2018 by Milicevic3306 Bhagirathi comment Share Follow See 1 comment 1 1 comment reply shashankrustagi commented Jan 29, 2021 reply Follow flag question is from COMPILER DESIGN, GRAMMARS in TOC and C mix 1 1 replyShare Please log in or register to add a comment.
7 7 votes this might Help you BHAVESH d shah answered Jun 28, 2017 BHAVESH d shah comment Share Follow See all 3 Comments 3 3 Comments reply akankshadewangan24 commented Jul 9, 2017 reply Follow flag why tree and list will not best? just was knowledge can u explain @BHAVESH 0 0 replyShare junk_mayavi commented Oct 2, 2017 reply Follow flag how can we use tree to check balanced paranthesis?? sombody please share. 1 1 replyShare Gupta731 commented Jul 7, 2020 reply Follow flag Suppose we traverse a tree top-down left to right, if we reach a node first time then we push that in stack. And when we visit that node for the last time, we pop the stack. Try this once. So ultimately you need a stack to keep a check on what you encountered in an expression. 0 0 replyShare Please log in or register to add a comment.
6 6 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 Rishi yadav answered Oct 3, 2017 Rishi yadav comment Share Follow 0 reply Please log in or register to add a comment.
4 4 votes correct answer should be Stack. to evaluate arthimatic expression we use stack data structure. Vijay Kumar Sharma 1 answered Oct 4, 2017 Vijay Kumar Sharma 1 comment Share Follow 0 reply Please log in or register to add a comment.