An empty stack and an empty queue undergo the following operations:
Stack: push(10), push(20), pop(), push(30)
Queue: enqueue(10), enqueue(20), dequeue(), enqueue(30)
Let be the sum of elements currently in the stack, and be the sum of elements currently in the queue. Which of the following correctly describes the relationship between and ?
C
Step-by-Step Solution
Key idea: This is a bounding question testing the fundamental difference between LIFO (stack) and FIFO (queue) removal constraints.
Step 1: Trace the Stack (LIFO).
- push(10) [10]
- push(20) [10, 20]
- pop() removes 20 (top). Stack is [10]
- push(30) [10, 30]
- Sum .
Step 2: Trace the Queue (FIFO).
- enqueue(10) [10]
- enqueue(20) [10, 20]
- dequeue() removes 10 (front). Queue is [20]
- enqueue(30) [20, 30]
- Sum .
Step 3: Compare and . , so .
Answer: