COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
One stack is enough
|
|
Two stacks are needed
|
|
As many stacks as the height of the expression tree are needed
|
|
A Turing machine is needed in the general case
|
Detailed explanation-1: -Explanation: Only one stack is enough to evaluate any expression or to convert one form to other form of expression. So, we get the answer using only one stack. One stack is enough to evaluate any expression without any embedded function call.
Detailed explanation-2: -Answers. Any expression can be converted into Postfix or Prefix form. Prefix and postfix evaluation can be done using a single stack.
Detailed explanation-3: -Step 1: Create an operand stack. Step 2: If the character is an operand, push it to the operand stack. Step 3: If the character is an operator, pop two operands from the stack, operate and push the result back to the stack. Step 4:After the entire expression has been traversed, pop the final result from the stack.
Detailed explanation-4: -Evaluation of postfix expression If it is a digit then, push it on to the stack. If it is an operator then, pop out the top most two contents from the stack and apply the operator on them. Later on, push the result on to stack. If the input symbol is ‘’, empty the stack.