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. It follows 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
If you push elements 1, 2, 3 in order, what will be the order when popping all elements?
The elements will come out in reverse order: 3, then 2, then 1, because of the LIFO principle.
intermediate Click to reveal answer
Why is a stack useful in programming?
Stacks help manage tasks like undo actions, function calls, and expression evaluation by keeping track of the order of operations.
Which operation adds an element to the top of a stack?
✗ Incorrect
Push adds an element to the top of the stack.
What does LIFO stand for?
✗ Incorrect
LIFO means Last In, First Out.
If a stack has elements [1, 2, 3] with 3 on top, which element will pop out first?
✗ Incorrect
The top element 3 will pop out first.
Which of these is NOT a typical stack operation?
✗ Incorrect
Sort is not a standard stack operation.
What real-life example best illustrates a stack?
✗ Incorrect
A pile of books where you take the top book first is like a stack.
Describe how the LIFO principle works in a stack with an example.
Think about a stack of plates or books.
You got /3 concepts.
List and explain the main operations of a stack and their effects.
Focus on what happens at the top of the stack.
You got /3 concepts.
