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: 20 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.
17 more cards in this chapter
Answer it here to see how it works. Nothing is recorded until you sign in.
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.
Stacks, Queues and Deques notes for GATE DA: 20 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
Match the following stack concepts with their precise descriptions:
Column I:
P. LIFO Principle
Q. Push Operation
R. Pop Operation
Column II:
D
Key idea: Direct matching of foundational stack terminology to their formal definitions.
Step 1: Analyze P (LIFO Principle). LIFO means Last-In-First-Out, which inherently restricts all access and modification to the "Top" element only. So, P matches with 1.
Step 2: Analyze Q (Push Operation). Push adds an element. The formal definition requires inserting at the top after verifying the stack is not full (checking for overflow). So, Q matches with 3.
Step 3: Analyze R (Pop Operation). Pop removes the top element. The formal definition is removing and returning the top element in time complexity. So, R matches with 2.
Answer: P-1, Q-3, R-2.
Match the following double-ended queue operations with their precise descriptions:
Column I:
P. insertFirst(e)
Q. removeLast()
Column II:
B
Key idea: Direct matching of deque operation names to their formal definitions.
Step 1: Analyze P (insertFirst(e)). The name explicitly states "insert" (add) and "First" (front end). This matches description 2.
Step 2: Analyze Q (removeLast()). The name explicitly states "remove" (delete) and "Last" (rear end). This matches description 1.
Step 3: Combine the matches: P matches 2, and Q matches 1.
Answer: P-2, Q-1
The access principle followed by a Stack data structure is called LIFO. What does LIFO stand for?
B
Key idea: This is a definition recall question, recognizable because it directly asks for the expansion of the acronym LIFO associated with stacks.
Step 1: Recall that a Stack follows the Last In, First Out principle. The most recently added element is the first one to be removed.
Step 2: Match this to the options. "Last In, First Out" is the correct expansion.
Answer: Option B
A stack contains the elements from bottom to top. Which element(s) can be directly accessed without removing any other element?
D
In a stack simulation, a variable is initialized to . The loop condition is while (x < 3). Inside the loop, Push(x) is executed, followed by x = x + 1. After the loop terminates, what is the minimum number of Pop() operations required to completely empty the stack?
C
Key idea: Simulate the loop to determine the final number of elements in the stack.
Step 1: Initial state: , Stack is empty.
Step 2: Iteration 1: (True). Push(0). Stack: . becomes .
Step 3: Iteration 2: (True). Push(1). Stack: . becomes .
Step 4: Iteration 3: (True). Push(2). Stack: . becomes .
Step 5: Iteration 4: (False). Loop terminates.
Step 6: The stack contains exactly 3 elements. To completely empty it, exactly 3 Pop() operations are required.
Answer: 3
An empty stack undergoes a sequence of operations. If the final stack contains exactly elements, and the total number of Push operations performed was , how many Pop operations must have been successfully executed, assuming no underflow occurred?
C
Key idea: Reverse engineering the final stack size using the net change formula.
Step 1: The fundamental relationship for stack size is: Final Size = Total Pushes - Total Successful Pops.
Step 2: We are given: Final Size = , Total Pushes = .
Step 3: Substitute the values into the formula: .
Step 4: Solve for Total Pops: .
Answer: 2
In an array-based deque implementation of size , when computing the new rear index after an insertLast operation, what is the minimum number of modulo () operations required in the index update formula to correctly handle the boundary wrap-around?
B
Key idea: Understanding the circular array index update mechanism for deques.
Step 1: In an array-based deque, the rear index must wrap around to when it reaches the end of the array (index ).
Step 2: The standard formula to achieve this wrap-around is .
Step 3: This formula explicitly uses exactly one modulo operation per index update to ensure the boundary is handled correctly.
Answer: 1
An initially empty standard queue undergoes a sequence of operations. If the final queue contains exactly elements, and the total number of Enqueue operations performed was , how many successful Dequeue operations must have been executed?
A
Key idea: Reverse engineering the final queue size using the net change formula.
Step 1: The fundamental relationship for queue size is: Final Size = Total Enqueues - Total Successful Dequeues.
Step 2: We are given: Final Size = , Total Enqueues = .
Step 3: Substitute the values into the formula: .
Step 4: Solve for Total Dequeues: .
Answer: 3