SME
Data Structures & Algorithms · Problem type
Evaluate a postfix expression
Use this for “Evaluate the postfix expression 3 4 + 2 × 7 − with a stack.”
Put in order
Put the stack operations for 3 4 + 2 × 7 − in order.
1
?
2
?
3
?
4
?
5
?
6
?
7
?
Assumptions
•
Postfix writes each operator after its two operands, so no brackets are needed.
•
Read left to right: a number is pushed; an operator pops two numbers and pushes its result.
•
The first number popped is the right operand: for − it is taken away from the second.
•
At the end the stack holds one number, the value of the expression.
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.
Related lessons
Lists, stacks and queues
Main lesson
Circular queue indices
Use this for “A circular queue has 8 slots, its front at slot 6 and 4 items. Where is the last item, and where does the next one go?”
Address of an array element
Use this for “A two-dimensional array of 8-byte numbers starts at address 2000 and has 10 columns. Where is element (3, 4)?”
Cost of a growing array
Use this for “An array starts with 1 slot and doubles when full. How many items are copied while 1000 are pushed?”