Recall & Review
beginner
What does it mean when a stack is empty?
A stack is empty when it has no elements inside it. This means there is nothing to pop or peek.
Click to reveal answer
beginner
How can you check if a stack is full in a fixed-size stack?
A stack is full when the number of elements reaches its maximum capacity. You check if the top pointer equals the maximum size minus one.
Click to reveal answer
beginner
Why is it important to check if a stack is empty before popping?
Checking if a stack is empty before popping prevents errors because you cannot remove an element from an empty stack.
Click to reveal answer
beginner
What is the typical way to represent the 'top' of a stack in code?
The 'top' is usually an index or pointer that shows the position of the last added element in the stack.
Click to reveal answer
beginner
In a stack implemented with a list and a max size, what condition checks if the stack is full?
If the length of the list equals the max size, the stack is full.
Click to reveal answer
What does the condition 'top == -1' usually mean in a stack?
✗ Incorrect
When top is -1, it means no elements have been added yet, so the stack is empty.
If a stack has max size 5, which condition means it is full?
✗ Incorrect
Since indexing starts at 0, top == 4 means 5 elements are in the stack, so it is full.
Why should you check if a stack is empty before popping?
✗ Incorrect
Popping from an empty stack causes errors, so checking prevents that.
Which of these is NOT a sign that a stack is full?
✗ Incorrect
top == -1 means the stack is empty, not full.
What is the initial value of 'top' in an empty stack?
✗ Incorrect
top starts at -1 to indicate no elements are present.
Explain how to check if a stack is empty or full in a fixed-size stack.
Think about what the 'top' index means when the stack has no elements or is at capacity.
You got /4 concepts.
Why is it important to check stack state before push or pop operations?
Consider what happens if you try to remove from empty or add to full stack.
You got /4 concepts.