Data Structures

Stacks — Practice MCQs for CCAT

20 Questions Section B: Programming Data Structures

Practice 20 Stacks multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.

Q1.
Stack follows which principle?
AFIFO
BLIFO
CRandom
DPriority
Show Answer & Explanation

Correct Answer: B — LIFO

Stack follows LIFO - Last In First Out principle.

Q2.
Push and Pop operations in stack take:
AO(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: A — O(1)

Push and Pop are O(1) as they operate only on top of stack.

Q3.
Which application does NOT use stack?
AFunction calls
BUndo operation
CBrowser history
DCPU scheduling
Show Answer & Explanation

Correct Answer: D — CPU scheduling

CPU scheduling uses queues, not stacks.

Q4.
Infix to Postfix conversion uses:
AQueue
BStack
CArray only
DLinked List
Show Answer & Explanation

Correct Answer: B — Stack

Stack is used to hold operators during infix to postfix conversion.

Q5.
Postfix expression evaluation uses:
AOne stack
BTwo stacks
CQueue
DNo data structure
Show Answer & Explanation

Correct Answer: A — One stack

Postfix evaluation needs one stack to hold operands.

Q6.
To check balanced parentheses, we use:
AQueue
BStack
CTree
DGraph
Show Answer & Explanation

Correct Answer: B — Stack

Stack matches opening brackets with closing brackets.

Q7.
Stack overflow occurs when:
AStack is empty
BPop from empty stack
CPush to full stack
DPeek operation fails
Show Answer & Explanation

Correct Answer: C — Push to full stack

Stack overflow happens when pushing to a stack that is already full.

Q8.
Stack underflow occurs when:
AStack is full
BPop from empty stack
CPush succeeds
DMultiple pushes
Show Answer & Explanation

Correct Answer: B — Pop from empty stack

Stack underflow happens when trying to pop from an empty stack.

Q9.
Recursion internally uses:
AQueue
BStack
CHash table
DHeap
Show Answer & Explanation

Correct Answer: B — Stack

Recursion uses call stack to store function calls and local variables.

Q10.
Which traversal uses stack (non-recursive)?
ALevel order
BBFS
CDFS/Inorder/Preorder/Postorder
DNone
Show Answer & Explanation

Correct Answer: C — DFS/Inorder/Preorder/Postorder

DFS and tree traversals use stack for iterative implementation.

Q11.
Two stacks can be used to implement a:
ATree
BQueue
CGraph
DHash table
Show Answer & Explanation

Correct Answer: B — Queue

Two stacks can simulate a queue - one for enqueue operations and one for dequeue.

Q12.
The peek operation in stack:
ARemoves top element
BReturns top without removing
CAdds element
DEmpties stack
Show Answer & Explanation

Correct Answer: B — Returns top without removing

Peek returns the top element without removing it from the stack.

Q13.
Tower of Hanoi problem uses:
AQueue
BStack/Recursion
CHash table
DGraph
Show Answer & Explanation

Correct Answer: B — Stack/Recursion

Tower of Hanoi is solved using recursion which internally uses stack.

Q14.
Minimum number of stacks needed to implement a queue:
A1
B2
C3
D4
Show Answer & Explanation

Correct Answer: B — 2

Two stacks are sufficient to implement a queue efficiently.

Q15.
Which sorting algorithm uses stack?
AMerge sort
BQuick sort (iterative)
CBubble sort
DSelection sort
Show Answer & Explanation

Correct Answer: B — Quick sort (iterative)

Iterative quick sort uses explicit stack to store subarray boundaries.

Q16.
Stock span problem is solved using:
AQueue
BStack
CTree
DGraph
Show Answer & Explanation

Correct Answer: B — Stack

Stock span problem uses stack to find the span of stock prices efficiently.

Q17.
Next greater element problem uses:
AQueue
BStack
CHeap
DTree
Show Answer & Explanation

Correct Answer: B — Stack

Next greater element is efficiently solved using stack in O(n) time.

Q18.
In array implementation of stack, top is initialized to:
A0
B-1
C1
DArray size
Show Answer & Explanation

Correct Answer: B — -1

Top is initialized to -1 indicating empty stack. First push makes top = 0.

Q19.
A stack can be implemented using:
AOnly arrays
BOnly linked lists
CBoth arrays and linked lists
DNeither
Show Answer & Explanation

Correct Answer: C — Both arrays and linked lists

Stack can be implemented using both arrays and linked lists with their respective trade-offs.

Q20.
Reversing a string can be done using:
AQueue
BStack
CTree
DGraph
Show Answer & Explanation

Correct Answer: B — Stack

Push all characters to stack, then pop them to get reversed string (LIFO property).