0
0
DSA Pythonprogramming~5 mins

Check if Stack is Empty or Full in DSA Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe stack is full
BThe stack is corrupted
CThe stack has one element
DThe stack is empty
If a stack has max size 5, which condition means it is full?
Atop == 0
Btop == 4
Ctop == 5
Dtop == -1
Why should you check if a stack is empty before popping?
ATo avoid removing from an empty stack
BTo avoid adding elements
CTo increase stack size
DTo reset the stack
Which of these is NOT a sign that a stack is full?
Atop == -1
Blength of stack list == max_size
CNo more space to push
Dtop == max_size - 1
What is the initial value of 'top' in an empty stack?
Amax_size
B0
C-1
D1
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.