Which of the following algorithms outputs a postfix expression, given a fully-pa
ID: 3715618 • Letter: W
Question
Which of the following algorithms outputs a postfix expression, given a fully-parenthesized infix expression as input?
Scan expression left to right.
If scanned item is operand, output immediately
If scanned item is operator, push it onto stack.
I scanned item is "(", output top of stack and pop stack.
Scan expression left to right.
If item scanned is operand, push it onto stack.
If item scanned is operator, pop top two items, apply operator to them, push result onto stack.
Scan expression left to right.
If scanned item is operand, output immediately
If scanned item is operator, push it onto stack.
I scanned item is ")", output top of stack and pop stack.
Scan expression left to right.
When an operand is encountered, push it onto a queue.
When an operator is encountered, pop the two front values from the queue, apply the operator to them, and push the result onto the queue
a. b.Scan expression left to right.
If scanned item is operand, output immediately
If scanned item is operator, push it onto stack.
I scanned item is "(", output top of stack and pop stack.
b. c.Scan expression left to right.
If item scanned is operand, push it onto stack.
If item scanned is operator, pop top two items, apply operator to them, push result onto stack.
c. a.Scan expression left to right.
If scanned item is operand, output immediately
If scanned item is operator, push it onto stack.
I scanned item is ")", output top of stack and pop stack.
d. d.Scan expression left to right.
When an operand is encountered, push it onto a queue.
When an operator is encountered, pop the two front values from the queue, apply the operator to them, and push the result onto the queue
Explanation / Answer
ANSWER : Here Option(C) as
Scan expression left to right.
If scanned item is operand, output immediately
If scanned item is operator, push it onto stack.
I scanned item is ")", output top of stack and pop stack.
is correct to convert an infix to postfix.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.