Recall & Review
beginner Click to reveal answer
What is a stack in simple terms?
A stack is like a pile of plates where you can only add or remove the top plate. It follows the Last In, First Out (LIFO) rule.
beginner Click to reveal answer
Why do we need a stack in programming?
Stacks help manage tasks that need to be done in reverse order, like undo actions, function calls, or checking matching brackets.
intermediate Click to reveal answer
What problem does a stack solve when dealing with function calls?
It keeps track of which function called which, so when a function finishes, the program knows where to return next.
intermediate Click to reveal answer
How does a stack help in undo operations?
Each action is saved on the stack. When undo is pressed, the last action is removed and reversed, following LIFO order.
beginner Click to reveal answer
What is a real-life example of a stack?
A stack of books where you can only take the top book off or add a new book on top.
What order does a stack follow?
✗ Incorrect
Stacks follow Last In, First Out (LIFO), meaning the last item added is the first to be removed.
Which of these is NOT a common use of a stack?
✗ Incorrect
Stacks are not typically used for sorting numbers; other data structures like arrays or heaps are used for sorting.
In a stack, where do you add new items?
✗ Incorrect
New items are always added at the top of the stack.
What happens when you pop an item from a stack?
✗ Incorrect
Popping removes the top item from the stack.
Why is a stack useful for checking matching brackets?
✗ Incorrect
A stack helps by remembering the last opened bracket so it can be matched with the next closing bracket.
Explain why a stack is important for managing function calls in a program.
Think about how the program remembers where to go back after a function ends.
You got /3 concepts.
Describe a real-life situation where a stack is used and how it works.
Imagine a pile of something you can only take from the top.
You got /3 concepts.
