Consider the process of balancing symbols using stack. What characters will be pushed into the stack?
A.Operators
B. Elements in the expression
C.Open brackets
D. Closing brackets
Answers
Answer:
How can stacks be used for checking balancing of symbols?
If the character read is not a symbol to be balanced, ignore it.
If the character is an opening delimiter like ( , { or [ , PUSH it into the stack.
If it is a closing symbol like ) , } , ] , then if the stack is empty report an error, otherwise POP the stack.
Answer:
The answer to the given question is:
C. Open brackets
Explanation:
Stacks are utilized when there is a lengthy-expression to be analyzed with multiple brackets to direct us as to which operations should be performed first.
Stacks now work on the last in first out principle, which means that only the pieces at the end of a stack can pop out. For example, in a stack of books, you can only extract the book at the top.
This concept is used in brackets matching, in which opening parentheses are pushed into the stack & closing parentheses are popped out; if all of the parentheses are covered and our stack is empty, we claim that bracket matching was successful.
#SPJ2