Recall & Review
beginner Click to reveal answer
What is a stack in data structures?
A stack is a collection where elements are added and removed only from the top, following the Last In, First Out (LIFO) principle.
beginner Click to reveal answer
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 take the top plate first.
beginner Click to reveal answer
What are the two main operations of a stack?
The two main operations are Push (to add an item on top) and Pop (to remove the top item).
beginner Click to reveal answer
Why is a stack compared to a stack of plates?
Because you add plates on top and remove plates from the top, just like a stack adds and removes elements from the top only.
intermediate Click to reveal answer
What happens if you try to pop from an empty stack?
It causes an underflow error because there are no elements to remove.
Which operation adds an element to the top of a stack?
✗ Incorrect
Push adds an element on top of the stack.
What does LIFO stand for?
✗ Incorrect
LIFO means the last element added is the first one removed.
If you push 1, then 2, then 3 onto a stack, what will be popped first?
✗ Incorrect
3 is the last pushed, so it is popped first.
Which of these is NOT a stack operation?
✗ Incorrect
Enqueue is used in queues, not stacks.
What error occurs when popping from an empty stack?
✗ Incorrect
Underflow happens when removing from an empty stack.
Describe how a stack works using a real-life example.
Think about how you add and remove plates from a pile.
You got /4 concepts.
Explain what happens step-by-step when you push and then pop elements in a stack.
Imagine placing and taking books from a pile.
You got /4 concepts.
