Recall & Review
beginner
What is a stack in data structures?
A stack is a collection where elements are added and removed only from one end called the top. It follows the Last In, First Out (LIFO) principle.
Click to reveal answer
beginner
Explain the LIFO principle in simple terms.
LIFO means the last item you put in is the first one you take out, like a stack of plates where you add and remove plates from the top.
Click to reveal answer
beginner
Which operations are common in a stack?
The two main operations are push (to add an item on top) and pop (to remove the top item).
Click to reveal answer
intermediate
What happens if you try to pop from an empty stack?
This is called underflow. It means there is no item to remove because the stack is empty.
Click to reveal answer
intermediate
Visualize the stack after these operations: push(1), push(2), pop(), push(3). What is the stack content from top to bottom?
After push(1) and push(2), stack is 2 (top) -> 1. Then pop() removes 2, stack is 1. Then push(3), stack is 3 (top) -> 1.
Click to reveal answer
What does LIFO stand for in stack operations?
✗ Incorrect
LIFO means the last element added is the first one removed, which is the core principle of stacks.
Which operation adds an element to the top of the stack?
✗ Incorrect
Push adds an element to the top of the stack.
If a stack has elements [5 (top), 3, 2], what will be the top after one pop operation?
✗ Incorrect
Pop removes the top element (5), so the new top is 3.
What is the result of popping from an empty stack called?
✗ Incorrect
Underflow happens when you try to pop from an empty stack.
Which real-life example best represents a stack?
✗ Incorrect
A pile of books where you add and remove from the top follows the LIFO principle like a stack.
Describe what a stack is and how the LIFO principle works using a simple real-life example.
Think about how you add and remove items from a pile.
You got /3 concepts.
Explain the push and pop operations in a stack and what happens if you pop from an empty stack.
Consider what adding and removing items from the top means.
You got /3 concepts.