It adds a new element to the top of the stack, increasing its size by one.
Click to reveal answer
beginner
In a stack, what happens if you try to push an element when the stack is full?
This situation is called stack overflow, and the push operation cannot add the new element.
Click to reveal answer
beginner
What is the time complexity of the push operation on a stack?
The push operation runs in O(1) time because it only adds an element at the top without traversing the stack.
Click to reveal answer
beginner
Show the state of the stack after pushing elements 5, then 10, then 15.
Stack top -> 15 -> 10 -> 5 -> null
Click to reveal answer
beginner
Why is the stack called LIFO?
Because the last element pushed onto the stack is the first one to be removed, following Last In First Out order.
Click to reveal answer
What does the push operation do in a stack?
AChecks if the stack is empty
BRemoves an element from the bottom
CAdds an element to the top
DClears all elements
✗ Incorrect
Push adds a new element to the top of the stack.
What is stack overflow?
AStack has only one element
BTrying to pop when stack is empty
CStack is empty
DTrying to push when stack is full
✗ Incorrect
Stack overflow happens when pushing to a full stack.
What is the time complexity of push operation?
AO(1)
BO(log n)
CO(n^2)
DO(n)
✗ Incorrect
Push runs in constant time O(1).
If stack is empty, what is the top after pushing 7?
Anull
B7
C0
DUndefined
✗ Incorrect
After pushing 7, top points to 7.
Which order does stack follow?
ALIFO
BFIFO
CRandom
DSorted
✗ Incorrect
Stack follows Last In First Out (LIFO) order.
Explain the push operation on a stack and what happens when the stack is full.
Think about adding an item on top and what limits the stack size.
You got /4 concepts.
Describe how the stack looks after pushing elements 3, 6, and 9 in that order.
Visualize stacking plates one on top of another.
You got /3 concepts.
Practice
(1/5)
1. What does the push operation do in a stack?
easy
A. Checks if the stack is empty
B. Adds an element to the top of the stack
C. Removes the top element from the stack
D. Returns the bottom element of the stack
Solution
Step 1: Understand stack operations
A stack is a data structure where elements are added or removed from the top only.
Step 2: Define push operation
The push operation adds a new element on top of the existing elements in the stack.
Final Answer:
Adds an element to the top of the stack -> Option B
Quick Check:
Push means add on top = C [OK]
Hint: Push always adds on top of stack [OK]
Common Mistakes:
Confusing push with pop operation
Thinking push removes elements
Mixing stack with queue operations
2. Which of the following is the correct syntax to push an element 5 onto a stack named s in C?
easy
A. s.push = 5;
B. s.push(5);
C. push(5, s);
D. push(s, 5);
Solution
Step 1: Understand typical C stack push syntax
In C, stack operations are usually functions where the stack is passed as the first argument.
Step 2: Match syntax with parameters
The correct function call to push 5 onto stack s is push(s, 5);.
Final Answer:
push(s, 5); -> Option D
Quick Check:
Function push(stack, value) = A [OK]
Hint: In C, function push(stack, value) is standard [OK]
Common Mistakes:
Using object.method syntax (not C style)
Swapping argument order
Assigning value instead of calling function
3. What will be the content of the stack after executing the following code?
int stack[5];
int top = -1;
// Push function
void push(int val) {
if(top < 4) {
top++;
stack[top] = val;
}
}
push(10);
push(20);
push(30);
medium
A. [10, 20, 30]
B. [30, 20, 10]
C. [10, 20]
D. Empty stack
Solution
Step 1: Trace each push call
Initially, top = -1. After push(10), top=0, stack[0]=10. After push(20), top=1, stack[1]=20. After push(30), top=2, stack[2]=30.
Step 2: List stack content from bottom to top
Stack elements from index 0 to top (2) are [10, 20, 30].
Final Answer:
[10, 20, 30] -> Option A
Quick Check:
Push adds at top increasing index = B [OK]
Hint: Stack stores pushed elements in order at increasing top index [OK]
Common Mistakes:
Reversing order of elements
Confusing top index with element values
Assuming stack is empty after pushes
4. Identify the error in the following push function for a stack of size 3:
int stack[3];
int top = 0;
void push(int val) {
if(top <= 3) {
stack[top] = val;
top++;
}
}
medium
A. Condition should be top < 3, not top <= 3
B. top should be incremented before assignment
C. stack array size should be 4
D. top should start at -1, not 0
Solution
Step 1: Analyze top and condition
top starts at 0, which is valid for empty stack at index 0. The condition allows top to be 3, which is out of bounds for stack[3] (indices 0 to 2).
Step 2: Correct the condition
Change condition to top < 3 to prevent overflow and invalid access.
Final Answer:
Condition should be top < 3, not top <= 3 -> Option A
Quick Check:
Stack max index 2 means top < 3 [OK]
Hint: Check array bounds: top must be less than size [OK]
Common Mistakes:
Allowing top to equal array size causing overflow
Starting top at -1 but not adjusting code
Incrementing top before assignment causing skip
5. Given a stack implemented with an array of size 4 and top = 2 currently, what will happen if we try to push two more elements without popping? Choose the correct behavior.
hard
A. Both pushes fail immediately due to full stack
B. Both pushes succeed, stack size automatically increases
C. First push succeeds, second push causes stack overflow
D. First push causes overflow, second push is not attempted
Solution
Step 1: Understand current stack state
Array size is 4, so valid indices are 0 to 3. top=2 means top element is at index 2, so one slot remains at index 3.
Step 2: Push two elements
First push increments top to 3 and stores element at index 3 (valid). Second push tries to increment top to 4, which is out of bounds, causing overflow.
Final Answer:
First push succeeds, second push causes stack overflow -> Option C
Quick Check:
Array size 4, top max index 3, overflow after that [OK]
Hint: Stack size fixed; overflow after last index [OK]
Common Mistakes:
Assuming stack auto-expands
Thinking both pushes fail immediately
Confusing top index with count
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.