Practice 20 Stacks multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
Show Answer & Explanation
Correct Answer: B — LIFO
Stack follows LIFO - Last In First Out principle.
Show Answer & Explanation
Correct Answer: A — O(1)
Push and Pop are O(1) as they operate only on top of stack.
Show Answer & Explanation
Correct Answer: D — CPU scheduling
CPU scheduling uses queues, not stacks.
Show Answer & Explanation
Correct Answer: B — Stack
Stack is used to hold operators during infix to postfix conversion.
Show Answer & Explanation
Correct Answer: A — One stack
Postfix evaluation needs one stack to hold operands.
Show Answer & Explanation
Correct Answer: B — Stack
Stack matches opening brackets with closing brackets.
Show Answer & Explanation
Correct Answer: C — Push to full stack
Stack overflow happens when pushing to a stack that is already full.
Show Answer & Explanation
Correct Answer: B — Pop from empty stack
Stack underflow happens when trying to pop from an empty stack.
Show Answer & Explanation
Correct Answer: B — Stack
Recursion uses call stack to store function calls and local variables.
Show Answer & Explanation
Correct Answer: C — DFS/Inorder/Preorder/Postorder
DFS and tree traversals use stack for iterative implementation.
Show Answer & Explanation
Correct Answer: B — Queue
Two stacks can simulate a queue - one for enqueue operations and one for dequeue.
Show Answer & Explanation
Correct Answer: B — Returns top without removing
Peek returns the top element without removing it from the stack.
Show Answer & Explanation
Correct Answer: B — Stack/Recursion
Tower of Hanoi is solved using recursion which internally uses stack.
Show Answer & Explanation
Correct Answer: B — 2
Two stacks are sufficient to implement a queue efficiently.
Show Answer & Explanation
Correct Answer: B — Quick sort (iterative)
Iterative quick sort uses explicit stack to store subarray boundaries.
Show Answer & Explanation
Correct Answer: B — Stack
Stock span problem uses stack to find the span of stock prices efficiently.
Show Answer & Explanation
Correct Answer: B — Stack
Next greater element is efficiently solved using stack in O(n) time.
Show Answer & Explanation
Correct Answer: B — -1
Top is initialized to -1 indicating empty stack. First push makes top = 0.
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.
Show Answer & Explanation
Correct Answer: B — Stack
Push all characters to stack, then pop them to get reversed string (LIFO property).