Which of the following data structures is most suitable for evaluating postfix expressions?
Which of the following data structures is most suitable for evaluating postfix expressions? Correct Answer Stacks
Stack data structure is suitable for evaluating postfix expression.
Stack : Stack is a linear data structure in which elements are inserted and deleted from one end only i.e. top of the stack. It follows a order to insert the elements into stack which is known as LIFO (Last in first out). Operations that are performed on a stack are : Push , Pop and peek.
Applications of stack :
- Stack can be used for evaluating arithmetic expression.(Postfix, prefix evaluation).
- It can be used for conversion from one expression to another.
- It can be used to check matching parenthesis in any expression.
- It can be used for memory management.
- It can undo the operation of a document editor or similar environment.
- It is used for backtracking.
- It keeps track of page visiting history of a web user.
- It is used in the implementation of recursive procedures.
Evaluation rule of postfix expression :
1) While reading the expression from left to right, push the element in the stack if it is an operand.
2) Pop the two operands from the stack, if the element is an operator and evaluate it.
3) Push back the result of evaluation. Repeat till the end of expression.