The Gateway to Computer Science Excellence
+24 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
in DS by
edited by | 3.3k views

2 Answers

+27 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. is a good read.

edited by

Hello Rajesh

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

Attaching source for detailed answer.


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)


+26 votes

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.


Point to be noted: Right parenthesis ')' is pushed on to the stack neither print on to the screen. Left parenthesis '(' always go on to the stack but not printed. 

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,504 answers
95,336 users