0
0
Intro to Computingfundamentals~20 mins

Stacks (last-in, first-out) in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stack Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
trace
intermediate
2:00remaining
Trace the stack operations and find the top element
Consider a stack initially empty. The following operations are performed in order:

1. Push 5
2. Push 10
3. Pop
4. Push 7
5. Push 3
6. Pop

What is the top element of the stack after these operations?
A3
B10
C5
D7
Attempts:
2 left
💡 Hint
Remember, pop removes the last pushed item, and push adds to the top.
🧠 Conceptual
intermediate
1:30remaining
Identify the correct property of a stack
Which of the following best describes the behavior of a stack data structure?
AFirst-in, first-out (FIFO)
BLast-in, first-out (LIFO)
CRandom access to any element
DSorted order insertion
Attempts:
2 left
💡 Hint
Think about which element is removed first when you pop from a stack.
Comparison
advanced
2:00remaining
Compare stack and queue behaviors
Which statement correctly compares a stack and a queue?
AStacks remove elements in LIFO order; queues remove elements in FIFO order.
BStacks and queues both remove elements in the order they were added.
CStacks remove elements in FIFO order; queues remove elements in LIFO order.
DStacks allow random access; queues only allow access to the last element.
Attempts:
2 left
💡 Hint
Recall the order in which elements are removed from each data structure.
identification
advanced
2:00remaining
Identify the error in stack operation code
Given the following pseudocode for stack operations:
stack = []
stack.push(1)
stack.push(2)
stack.pop()
stack.pop()
stack.pop()

What error will occur when this code runs?
Intro to Computing
stack = []
stack.push(1)
stack.push(2)
stack.pop()
stack.pop()
stack.pop()
AAttributeError: 'list' object has no attribute 'push'
BSyntaxError: invalid syntax
CIndexError: popping from empty stack
DNo error, code runs successfully
Attempts:
2 left
💡 Hint
Check if the method names used for list operations are correct in Python.
🚀 Application
expert
3:00remaining
Determine the output of stack-based expression evaluation
A stack is used to evaluate the postfix expression: 3 4 2 * 1 5 - 2 3 ^ ^ / +

What is the final result after evaluating this expression using a stack?
A5.5
BError: invalid expression
C3.0001220703125
D7.0
Attempts:
2 left
💡 Hint
Evaluate step-by-step using stack: push numbers, pop two for operators, apply operator, push result back.