Recall & Review
beginner
What is the push operation in a stack?
The push operation adds a new element to the top of the stack, increasing its size by one.
Click to reveal answer
beginner
In a stack, where is the new element added during a push operation?
The new element is added at the top of the stack.
Click to reveal answer
intermediate
What happens if you try to push an element onto a full stack?
If the stack is full, pushing an element causes a stack overflow error, meaning no more elements can be added.
Click to reveal answer
beginner
Show the state of the stack after pushing elements 1, then 2, then 3 onto an empty stack.
After pushing 1: 1 -> null<br>After pushing 2: 2 -> 1 -> null<br>After pushing 3: 3 -> 2 -> 1 -> null
Click to reveal answer
intermediate
Why is the push operation considered a constant time operation (O(1))?
Because it only adds an element at the top without needing to move other elements, so the time taken does not depend on the stack size.
Click to reveal answer
What does the push operation do in a stack?
✗ Incorrect
Push adds a new element to the top of the stack.
If a stack currently has elements 5 -> 4 -> null, what will be the stack after push(6)?
✗ Incorrect
Push adds the new element 6 at the top, so it becomes 6 -> 5 -> 4 -> null.
What error occurs when pushing onto a full stack?
✗ Incorrect
Stack Overflow happens when trying to push onto a full stack.
Which data structure principle does push operation follow?
✗ Incorrect
Stack follows Last In First Out (LIFO), so push adds to the top.
What is the time complexity of the push operation on a stack?
✗ Incorrect
Push operation takes constant time O(1) because it only adds one element at the top.
Explain the push operation on a stack and what happens to the stack after pushing an element.
Think about how a stack grows when you add something.
You got /3 concepts.
Describe what happens when you try to push an element onto a full stack and why it is important to check for this condition.
Consider what happens if the stack has no room left.
You got /3 concepts.