Recall & Review
beginner
What is a stack in data structures?
A stack is a collection where elements are added and removed in a last-in, first-out (LIFO) order, like a stack of plates.
Click to reveal answer
beginner
Why might using an array directly be risky for stack operations?
Using an array directly can lead to errors like accessing invalid positions or forgetting to check if the stack is full or empty, causing bugs or crashes.
Click to reveal answer
intermediate
What does stack abstraction mean?
Stack abstraction means hiding the details of how the stack works inside, and only allowing access through specific operations like push and pop.
Click to reveal answer
beginner
Name two main operations of a stack.
Push (add an element to the top) and Pop (remove the top element).
Click to reveal answer
intermediate
How does stack abstraction help in programming?
It prevents mistakes by controlling how data is added or removed, makes code easier to understand, and allows changing the internal structure without affecting the rest of the program.
Click to reveal answer
What order does a stack follow when removing elements?
✗ Incorrect
Stacks remove the most recently added element first, which is called Last In, First Out (LIFO).
Why is it better to use stack abstraction instead of directly using arrays?
✗ Incorrect
Stack abstraction hides how the stack works and controls access, reducing errors and making code safer.
Which operation adds an element to the stack?
✗ Incorrect
Push adds an element to the top of the stack.
What problem can happen if you use an array directly for stack without checks?
✗ Incorrect
Without checks, you might add too many elements (overflow) or remove from an empty stack (underflow), causing errors.
Which of these is NOT a benefit of stack abstraction?
✗ Incorrect
Stack abstraction simplifies code management and reduces errors; it does not make code more complex.
Explain why using a stack abstraction is better than using an array directly for stack operations.
Think about safety and hiding details.
You got /4 concepts.
Describe the main difference between how a stack and an array work when adding and removing elements.
Focus on order and access rules.
You got /4 concepts.
