+20 votes
2.5k views

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
in DS
edited | 2.5k views
0

## 2 Answers

+22 votes
Best answer

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.

by Boss (23.5k points)
edited
0

Hello Rajesh

Are you sure to evaluate prefix expression we need only one stack ?

Attaching source for detailed answer.

https://en.wikibooks.org/wiki/Data_Structures/Stacks_and_Queues

+1

Parse tree is not irrelevant, it is relevant. Only thing is it occupies more space than a normal stack implementation. We can get a infix to postfix by doing a post order traversal of a parse tree. As the question is about efficiency

Space(Parse-Tree) > Space(Stack)

+25 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.
by Boss (19.9k points)

0 votes
1 answer
2
0 votes
1 answer
3
+6 votes
6 answers
4
+1 vote
1 answer
5
+1 vote
3 answers
6