Recall & Review
beginner
What is a stack in data structures?
A stack is a collection of elements that follows the Last In, First Out (LIFO) principle, where the last element added is the first one to be removed.
Click to reveal answer
beginner
What does the 'push' operation do in a stack?
The 'push' operation adds a new element to the top of the stack.
Click to reveal answer
beginner
What is the purpose of the 'pop' operation in a stack?
The 'pop' operation removes and returns the top element from the stack.
Click to reveal answer
beginner
Explain the 'peek' operation in a stack.
The 'peek' operation returns the top element of the stack without removing it, allowing you to see what is on top.
Click to reveal answer
beginner
Why is the stack called Last In, First Out (LIFO)?
Because the last element pushed (added) onto the stack is the first one to be popped (removed), like a stack of plates where you take the top plate first.
Click to reveal answer
Which operation adds an element to the top of a stack?
✗ Incorrect
The 'push' operation adds a new element to the top of the stack.
What does the 'pop' operation do?
✗ Incorrect
The 'pop' operation removes and returns the top element from the stack.
What is the result of the 'peek' operation?
✗ Incorrect
The 'peek' operation returns the top element without removing it.
Which principle does a stack follow?
✗ Incorrect
A stack follows the Last In, First Out (LIFO) principle.
If you push elements 1, 2, 3 in order, which element will pop return first?
✗ Incorrect
The last pushed element (3) is the first to be popped in a stack.
Describe the three main operations of a stack and their effects.
Think about how you add, remove, and check the top item in a stack of objects.
You got /3 concepts.
Explain why a stack is called Last In, First Out (LIFO) with a real-life example.
Imagine a pile of books or plates and how you take them off.
You got /3 concepts.