The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+20 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 Veteran (52.1k points)
edited by | 2.5k views

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

by Boss (23.5k points)
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)


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

Related questions

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
49,807 questions
54,729 answers
79,913 users