Which of the following data structure is required to convert arithmetic expression in infix to its equivalent postfix notation?a.Queueb.Linked listc.Binary search treed.Stack
Question
Which of the following data structure is required to convert arithmetic expression in infix to its equivalent postfix notation?a.Queueb.Linked listc.Binary search treed.Stack
Solution 1
The data structure required to convert an arithmetic expression in infix to its equivalent postfix notation is d. Stack.
Here's a step-by-step explanation:
- Scan the infix expression from left to right.
- If the scanned character is an operand, output it.
- Else,
- If the precedence of the scanned operator is greater than the precedence of the operator in the stack(or the stack is empty), push it.
- Else, Pop the operator from the stack until the precedence of the scanned operator is less-equal to the precedence of the operator residing on the top of the stack. Push the scanned operator to the stack.
- If the scanned character is an '(', push it to the stack.
- If the scanned character is an ')', pop and output from the stack until an '(' is encountered. Pop and discard the '('.
- Repeat steps 2-6 until the expression is scanned.
- Pop and output from the stack until it is not empty.
Solution 2
The data structure required to convert an arithmetic expression in infix to its equivalent postfix notation is d. Stack.
Here's a step-by-step explanation:
- Scan the infix expression from left to right.
- If the scanned character is an operand, output it.
- Else,
- If the precedence of the scanned operator is greater than the precedence of the operator in the stack(or the stack is empty), push it.
- Else, Pop the operator from the stack until the precedence of the scanned operator is less-equal to the precedence of the operator residing on the top of the stack. Push the scanned operator to the stack.
- If the scanned character is an '(', push it to the stack.
- If the scanned character is an ')', pop and output from the stack until an '(' is encountered. Pop the '(' from the stack, but do not output it.
- Repeat steps 2-6 until infix expression is scanned.
- Pop and output from the stack until it is not empty.
Similar Questions
Which data structure is needed to convert infix notation to postfix notation? Tree Branch Stack Queue
Which data structure is needed to convert infix notation to postfix notation?*2 pointsTreeStackBranchQueue
Which data structure is needed to convert infix notation to postfix notation?
Write an algorithm for converting infix expression into postfix expression.
Stacks are used for converting infix expressions to postfix expressions. What is the postfix form of the infix expression "A + B * C"?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.