In a Stack data structure, the <code>Push</code> operation inserts a new element at which position?
A
Stacks, Queues and Deques notes for GATE DA: 23 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.
A Stack is a linear data structure that follows a particular order in which operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last Out).
Imagine a stack of books on a table:
To access Book A, you must first remove Book C, then Book B. The last item added (C) is the first one removed.
A stack supports two main atomic operations. In exam simulations, tracking these step-by-step is crucial.
| Operation | Description | Pre-condition Check | Time Complexity |
|---|---|---|---|
Push(x) |
Inserts element at the top. | Check for Overflow (Is stack full?) | |
Pop() |
Removes and returns the top element. | Check for Underflow (Is stack empty?) | |
Peek/Top |
Returns the top element without removing it. | Check for Underflow |
Let be a stack. Initially .
Push(10) (Top is 10)Push(20) (Top is 20)Pop() Returns 20, (Top is 10)top usually tracks the index of the current top element.
Consider the following pseudocode:
Create empty stack S
Set x=0, flag=0, sum=0
Push x onto S // S: [0]
while (S is not empty){
if (flag equals 0){
Set x = x+1
Push x onto S
}
if (x equals 8):
Set flag=1
if (flag equals 1){
x = Pop(S)
if (x is odd):
Pop(S) // Discard this value
Set sum = sum + x
}
}
Output sum
The loop runs, incrementing x and pushing it until x reaches 8.
Now . The first if block is skipped. We only evaluate the check and the block.
| Iteration | Stack Before | x = Pop(S) |
Is Odd? | Action | Stack After | |
|---|---|---|---|---|---|---|
| 1 | Yes | Pop (discards 6), | 7 | |||
| 2 | Yes | Pop (discards 4), | 12 | |||
| 3 | Yes | Pop (discards 2), | 15 | |||
| 4 | Yes | Pop (discards 0), | 16 |
Next iteration: is empty. Loop terminates.
In a Stack data structure, the <code>Push</code> operation inserts a new element at which position?
A
Which stack operation removes and returns the topmost element?
C
Push: Adds an element to the top. Does not remove.
- Peek (or Top): Returns the top element without removing it.
- Pop: Removes the top element and returns it.
- IsEmpty: Checks whether the stack is empty. Returns a boolean.
Step 2: The question asks for the operation that both removes and returns. Only Pop does both.
Answer: Option C
Stacks, Queues and Deques notes for GATE DA: 23 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.