Stack Basics and Operations MCQs: 12 Solved Questions with Step-by-Step Explanations

Test stack fundamentals through 12 exam MCQs on LIFO, TOP, array bounds, queue transfers and permutations. Complete traces make every state and answer checkable.

KnowledgeGate Team

Exam prep & CS education

Updated 3 Oct 20268 min read

Stack traces become fragile when TOP changes repeatedly, a queue appears, or an array grows towards lower indices. One missed state corrupts every later answer.

LIFO order, overflow and underflow, array and linked representations, stack-queue transfers, shared storage, permutations and queue construction all depend on explicit state. Use Coding & Skills for broader practice. Choose an option first, then record each stack state before reading the explanation.

Stack rules and the state-trace method

Rule

Meaning

Stack

Last in, first out (LIFO)

PUSH

Insert at TOP

POP

Remove and return TOP

PEEK

Read TOP without removing it

Underflow

Pop an empty stack

Overflow

Push a full fixed-capacity stack

For an array stack, empty means top = -1, full means top = N - 1, and push and pop are O(1). A linked stack keeps TOP at the head.

Trace a capacity 4 stack bottom to top. Begin with [], top = -1. push(10) gives [10], top = 0; push(20) gives [10, 20], top = 1; push(30) gives [10, 20, 30], top = 2. peek() returns 30 unchanged. pop() returns 30, leaving [10, 20], top = 1. push(40) gives [10, 20, 40], top = 2; push(50) fills [10, 20, 40, 50], top = 3. Another push(60) overflows. Always record contents and TOP.

Capacity-4 stack traced through push, peek and pop, ending with a blocked push that overflows.

Stack MCQs 1 to 3: operations, overflow and constant-time push

Question 1, TPSC 2025

Which of the following operations is not possible in a stack ?

  • A. Push

  • B. Pop

  • C. Peek

  • D. Delete from the middle

Answer: D.

In [10, 20, 30], push, pop and peek touch TOP (30). Deleting 20 is not a standard operation because 30 must be removed or bypassed first.

Question 2, Hexaware 2024

If the size of the stack is 10 and we try to add the 11th element in the stack then the condition is known as___

  • A. Underflow

  • B. Garbage collection

  • C. Overflow

  • D. None of the above

Answer: C.

A size 10 stack has positions 0 through 9. The 11th push causes overflow; pop() on [] causes underflow.

Question 3, Beltron Programmer 2025

What is the time complexity of the push() operation in an array-based stack?

  • A. O(1)

  • B. O(log n)

  • C. O(n log n)

  • D. O(n)

Answer: A.

With top = 6, pushing 42 checks capacity, sets top = 7, and writes A[7] = 42: O(1) work. A dynamic array may sometimes resize.

Stack MCQs 4 to 6: trace every push, pop and queue transfer

For the broader mixed-structure set, including the 10/20 version of this operation pattern, use Stacks and Queues MCQs: 12 Solved (GATE). Trace the 1/2 sequence below from bottom to top; the following question then adds a queue transfer.

Question 4, Indian Space Research Organization 2015

If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack, the sequence of popped out values

  • A. 2,2,1,1,2

  • B. 2,2,1,2,2

  • C. 2,1,2,2,1

  • D. 2,1,2,2,2

Answer: A.

Trace [] -> [1] -> [1,2]; pop outputs 2, leaving [1]; pushing 1 and 2 gives [1,1] -> [1,1,2]; three pops output 2,1,1, leaving []; push 2 gives [2], then pop outputs 2. Thus 2,2,1,1,2.

Queue Basics and Stack Mix MCQs works through the longer seven-item transfer in a table. This five-item BEL variant is shorter: the decisive point is the order in which E and D leave the queue and return to TOP.

Question 5, BEL 2007

The five items: A, B, C, D, and E are pushed in a stack, one after the other starting from A. The stack is popped four times and each element is inserted in a queue. Then two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

  • A. A

  • B. B

  • C. C

  • D. D

Answer: D.

The pushes produce [A,B,C,D,E], with E at TOP. Four pops leave [A] and enqueue E,D,C,B, E first. Dequeue and push E to get [A,E]; repeat with D for [A,E,D]. The next pop returns D.

Stack A to E popped into a queue, then E and D pushed back so the next pop returns D.

Question 6, UGC NET 2016

Consider the following operations performed on a stack of size 5 :

Push (a); Pop() ; Push(b); Push(c); Pop();

Push(d); Pop();Pop(); Push (e)

Which of the following statements is correct ?

  • A. Underflow occurs

  • B. Stack operations are performed smoothly

  • C. Overflow occurs

  • D. None of the above

Answer: B.

Trace [] -> [a] -> [] -> [b] -> [b,c] -> [b] -> [b,d] -> [b] -> [] -> [e]. No pop hits []; occupancy peaks at 2, below capacity 5. No error occurs.

Stack MCQs 7 to 9: array direction, valid TOP and linked representation

Question 7, Indian Space Research Organization 2020

A stack is implemented with an array of ‘A[0...N – 1]’ and a variable ‘pos’. The push and pop operations are defined by the following code.

Code
push (x)
  A[pos] ← x
  pos ← pos – 1
end push

pop ( )
  pos ← pos + 1
  return A[pos]
end pop

Which of the following will initialize an empty stack with capacity N for the above implementation ?

  • A. pos ← –1

  • B. pos ← 0

  • C. pos ← 1

  • D. pos ← N – 1

Answer: D.

The code writes before decrementing, so growth is towards smaller indices. For N = 4, start at pos = 3. Four pushes fill A[3], A[2], A[1], A[0], leaving pos = -1; every cell is used.

Question 8, RSSB 2022

Consider the following stack implemented using stack –

Code
#define SIZE 11
Struct STACK
{
    int arr[SIZE];
    int top = -1;
}

What would be the maximum value of top that does not cause the overflow of the stack?

  • A. 8

  • B. 9

  • C. 11

  • D. 10

Answer: D.

arr[11] has indices 0 through 10. From top = -1, the first item occupies 0 and the 11th occupies 10. Thus the maximum safe TOP is 10; 11 is outside the array.

Question 9, CDAC CCAT 2017

In the standard linked-list representation of a stack, where TOP points to the first node and links continue toward older stack elements, the null pointer of the last node in the list represents:

  • A. Beginning of the stack

  • B. Bottom of the stack

  • C. Middle of the stack

  • D. In between some value

Answer: B.

In TOP -> 42 -> 17 -> 9 -> null, links reach older elements. Node 9 has no successor, so null marks the bottom; the head is TOP.

Stack MCQs 10 to 12: shared arrays, permutations and queue construction

Question 10, GATE 2004

A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for “stack full” is

  • A. (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)

  • B. top1 + top2 = MAXSIZE

  • C. (top1= MAXSIZE/2) or (top2 = MAXSIZE)

  • D. top1= top2 -1

Answer: D.

Full means no gap remains between TOP positions. With MAXSIZE = 10, top1 = 6 and top2 = 7 are adjacent, so another push collides. Thus top1 = top2 - 1; a midpoint could waste cells.

Question 11, GATE 1994

Which of the following permutations can be obtained in the output (in the same order) using a stack assuming that the input is the sequence 1, 2, 3, 4, 5 in that order?

  • A. 3, 4, 5, 1, 2

  • B. 3, 4, 5, 2, 1

  • C. 1, 5, 2, 3, 4

  • D. 5, 4, 3, 1, 2

Answer: B.

Construct B: push 1,2,3, pop 3; push 4, pop 4; push 5, pop 5; then pop 2,1. A and D demand 1 while it is below 2. In C, after outputting 1 and stacking 2,3,4,5, popping 5 exposes 4, not 2.

Question 12, Goldman Sachs 2023

Suppose implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?

  • A. A queue cannot be implemented using this stack.

  • B. A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.

  • C. A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.

  • D. A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.

Answer: C.

Keep the queue front at TOP, so DEQUEUE is one POP. To append 30 to [10,20], use REVERSE, PUSH(30), REVERSE. TOP-to-bottom order becomes 10,20,30, so the next pop returns 10: three ENQUEUE instructions, one DEQUEUE instruction.

Common traps in stack operations

Trap

What fails

Replacement habit

TOP treated as a count

Q8 uses an invalid index

Write the valid range

Errors confused

Q2 and Q6 get reversed

Test full and empty separately

Queue read as LIFO

Q5 returns the wrong item

Mark front and rear

Upward growth assumed

Q7 starts at the wrong end

Read the code's direction

Midpoint fixed

Q10 wastes shared cells

Test TOP adjacency

Permutation guessed

Q11 accepts the impossible

Construct legal pushes and pops

Answer check and the next practice step

Answer key: 1-D, 2-C, 3-A, 4-A, 5-D, 6-B, 7-D, 8-D, 9-B, 10-D, 11-B, 12-C.

  • 10 to 12 correct: Move to mixed stack problems.

  • 7 to 9 correct: Repeat the representation or trace type you missed.

  • 0 to 6 correct: Rebuild LIFO, TOP, overflow and underflow first.

Redo Q4, Q5, Q10 and Q11 without options. Q4 checks a pure LIFO trace, Q5 adds a queue transfer, Q10 checks shared-array boundaries, and Q11 tests whether an output permutation is constructible.

Continue with DSA Using Java, or use Coding for Placements for placement practice. Record every stack state so each operation remains checkable.