• edited by
15,459 views
41 41 votes

Which of the following is essential for converting an infix expression to the postfix form efficiently?

  1. An operator stack
  2. An operand stack
  3. An operand stack and an operator stack
  4. A parse tree

4 Answers

Best answer
21 21 votes

First of all, this question must be clear in our mind and i.e. Why do we need to convert infix expression postfix expression?

Conventional notation is called infix notation. The arithmetic operators appears between two operands. Parentheses are required to specify the order of the operations. For example: a + (b * c).

 

Post fix notation (also, known as reverse Polish notation) eliminates the need for parentheses.

 

There are no precedence rules to learn, and parenthesis are never needed. Because of this simplicity, some popular hand-held calculators use postfix notation to avoid the complications of multiple sets of parentheses.

 

The operator is placed directly after the two operands it needs to apply. For example: a b c * +

 

You got the answer of Why?

Now, it's time to know what?

 

What is Operand Stack?

When we evaluate a given postfix expression, then we only push the operands into the stack but not any operator. So, the stack used in postfix evaluation called operand stack.
 

What is Operator Stack?

When we convert an infix notation into postfix notation, then we only push the operators into the stack but not any operand. So, stack used in the conversion from infix to postfix is called operator stack.

 

Algorithm to convert Infix into Postfix expression using operator stack:


Input is-

if( ‘(‘ )

    push in stack

if( ‘)’ )

     pop until left parenthesis is popped

if(operator)

    1.Lower priority is in input then pop

    2.Higher priority is in input then push

    3.Same r priority is pop except exponent Operator

if(Operand)

    Ignore


After conversion of Infix to postfix, we will evaluate postfix expression using Operand Stack only.

• selected by
64 64 votes

A. An operator stack    // Infix to ( Postfix or Prefix )

B. An operand stack    //Postfix or Prefix Evaluation

C. An operand stack and an operator stack //we never use two stacks

But for Prefix to (Infix or postfix)  OR   Postfix to (Infix or prefix)  We can use a stack where both operator and operand can present simultaneously

D. A parse tree  // Not relevant to this question

Hence, Option A is Answer.

http://condor.depaul.edu/ichu/csc415/notes/notes9/Infix.htm is a good read.

• edited by
27 27 votes
A.

we use operator stack (only operators are pushed as +, *, (, ), / ) for converting infix to postfix. And we use operand stack( operands such as 5,4,17 etc) for postfix evaluation.
Answer:
Position:
Show:

Related questions

73 73 votes
5 answers 5 answers
39.0k
39.0k views
Kathleen asked Sep 29, 2014
38,990 views
A priority queue $Q$ is used to implement a stack that stores characters. PUSH (C) is implemented as INSERT $(Q, C, K)$ where $K$ is an appropriate integer key chosen by ...
4 4 votes
0 0 answers
1.1k
1.1k views
Hardik1997 asked Jul 11, 2017
1,072 views
Which of the following is essential for converting an infix expression into postfix?a - An operator stackb - An operand stackc - both a and bd - A parse treeI understand ...
51 51 votes
4 answers 4 answers
24.5k
24.5k views
Kathleen asked Sep 21, 2014
24,485 views
The following postfix expression with single digit operands is evaluated using a stack:$$8 \ 2 \ 3 \ \;\hat{}\; ∕ \ 2 \ 3 * + 5 \ 1 * -$$Note that $\;\hat{}\;$ is the ...
38 38 votes
3 answers 3 answers
8.2k
8.2k views
Kathleen asked Sep 29, 2014
8,202 views
Consider the following piece of 'C' code fragment that removes duplicates from an ordered list of integers.Node *remove-duplicates (Node* head, int *j) { Node *t1, *t2; ...