PRACTICE • LEARN • GROW
Stack & Queue MCQs
Solve topic-wise placement questions and improve your skills.
Stack & Queue Progress
0 of 36 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
Which data structure adheres strictly to the LIFO (Last In First Out) principle?
A.
Stack
B.
Queue
C.
Priority Queue
D.
Deque
Explanation & Key
Correct Answer:
2
How can you implement a Queue using two Stacks such that enqueue is O(1) amortized?
A.
Push to both stacks simultaneously on every enqueue
B.
Push onto stack1; pop/peek from stack2 transferring elements from stack1 only when stack2 is empty
C.
Reverse stack2 on every push operation
D.
Sort stack1 after every push
Explanation & Key
Correct Answer:
3
Which data structure is optimal for solving the "Next Greater Element" problem in O(N) linear time?
A.
Binary Search Tree
B.
Min-Heap
C.
Monotonic Decreasing Stack
D.
Circular Queue
Explanation & Key
Correct Answer:
4
What is the time complexity to evaluate a Postfix (Reverse Polish) expression of length N using a stack?
A.
O(N^2)
B.
O(N log N)
C.
O(2^N)
D.
O(N)
Explanation & Key
Correct Answer:
5
What is the condition for a full queue in a Circular Queue of size CAPACITY with `front` and `rear` pointers?
A.
`(rear + 1) % CAPACITY == front`
B.
`rear == front`
C.
`rear + front == CAPACITY`
D.
`rear == CAPACITY - 1`
Explanation & Key
Correct Answer:
6
How can you design a Stack that supports `push`, `pop`, `top`, and `getMin` in O(1) time and O(N) space?
A.
Sort the stack on every push operation
B.
Use an auxiliary stack to store minimum values at each state (or encode `2 * x - minVal`)
C.
Use a binary heap to find minimum
D.
Traverse the entire stack on getMin call
Explanation & Key
Correct Answer:
7
Which graph traversal algorithm primarily uses a FIFO Queue?
A.
Depth-First Search (DFS)
B.
Dijkstra Algorithm without queue
C.
Breadth-First Search (BFS)
D.
Kosaraju Algorithm
Explanation & Key
Correct Answer:
8
In the Shunting-Yard algorithm (Dijkstra), what is the role of the operator stack when converting Infix to Postfix?
A.
It stores operands in reverse order
B.
It evaluates binary numbers directly
C.
It detects cyclic dependencies in graphs
D.
It enforces operator precedence and associativity by holding lower or equal precedence operators
Explanation & Key
Correct Answer:
9
What is the optimal time complexity to solve "Largest Rectangle in Histogram" using a monotonic stack?
A.
O(N)
B.
O(N^2)
C.
O(N log N)
D.
O(N sqrt(N))
Explanation & Key
Correct Answer:
10
What is a Deque (Double-Ended Queue)?
A.
A queue that sorts elements automatically
B.
A queue that allows insertion and deletion at both front and rear in O(1) time
C.
A queue restricted to holding only two items
D.
A stack that cannot be popped
Explanation & Key
Correct Answer:
11
What is the time complexity of the "Sliding Window Maximum" problem of size K across an array of size N using a monotonic Deque?
A.
O(N * K)
B.
O(N log K)
C.
O(N)
D.
O(K log N)
Explanation & Key
Correct Answer:
12
In CPU task scheduling, which data structure is most appropriate for Round-Robin scheduling?
A.
LIFO Stack
B.
Binary Search Tree
C.
Disjoint Set Union
D.
Circular FIFO Queue
Explanation & Key
Correct Answer:
13
What happens when a stack exceeds its allocated memory buffer in programming environments?
A.
Stack Overflow error
B.
Stack Underflow error
C.
Segmentation success
D.
The OS doubles RAM speed automatically
Explanation & Key
Correct Answer:
14
What is the prefix form of the infix expression `(A + B) * C`?
A.
`A B + C *`
B.
`* + A B C`
C.
`+ * A B C`
D.
`* A + B C`
Explanation & Key
Correct Answer:
15
How many stacks are required to implement a FIFO Queue if recursion is NOT allowed?
A.
1
B.
3
C.
2
D.
4
Explanation & Key
Correct Answer:
16
What is the amortized cost of pushing elements into a dynamic array (like C++ `std::vector` or Java `ArrayList`) that doubles capacity upon filling?
A.
O(N)
B.
O(log N)
C.
O(N^2)
D.
O(1)
Explanation & Key
Correct Answer:
17
Which problem can be solved using the "Valid Parentheses" stack-based approach in O(N) time?
A.
Matching opening and closing brackets `()`, `{}`, `[]` in code syntax
B.
Finding shortest paths in graphs
C.
Multiplying two matrices
D.
Sorting strings alphabetically
Explanation & Key
Correct Answer:
18
What is Priority Queue typically implemented with to achieve O(log N) insert and O(log N) extract-min?
A.
Linked List
B.
Binary Heap
C.
Circular Array
D.
Stack
Explanation & Key
Correct Answer:
19
In the Celebrity Problem (a person who is known by all but knows none), how can it be solved in O(N) time using a stack?
A.
Compute the transitive closure matrix in O(N^3)
B.
Sort candidates by age
C.
Push all candidates to stack; pop two, discard one based on `knows(A, B)`, push back until 1 remains, then verify
D.
Run Dijkstra algorithm from candidate 0
Explanation & Key
Correct Answer:
20
What is Stack Underflow?
A.
When stack memory exceeds heap memory
B.
When all elements in the stack are negative numbers
C.
When two threads push at the same time
D.
Attempting to pop or peek an element from an empty stack
Explanation & Key
Correct Answer:
21
How can a Queue be implemented using two Stacks such that push and pop have amortized O(1) time complexity?
A.
Enqueue pushes to Stack 1; Dequeue pops from Stack 2 (if Stack 2 is empty, transfer all elements from Stack 1 to Stack 2)
B.
Push to both stacks simultaneously on every operation
C.
Sort both stacks after each push
D.
Pop alternately from Stack 1 and Stack 2
Explanation & Key
Correct Answer:
22
What is the condition for a full queue in a Circular Queue of capacity C using front and rear indices (where rear points to the last inserted element)?
A.
rear == front
B.
(rear + 1) % C == front
C.
rear == C - 1
D.
front == 0
Explanation & Key
Correct Answer:
23
Which data structure is optimal for evaluating mathematical expressions in Postfix (Reverse Polish) Notation?
A.
Queue
B.
Stack
C.
Binary Search Tree
D.
Min-Heap
Explanation & Key
Correct Answer:
24
In the classic "Daily Temperatures" problem (finding how many days until a warmer temperature), which monotonic stack variant is used?
A.
Monotonically increasing stack of temperatures
B.
Monotonically decreasing stack of day indices
C.
Priority queue of temperature differences
D.
FIFO queue of dates
Explanation & Key
Correct Answer:
25
What is a Double-Ended Queue (Deque)?
A.
A queue that holds twice as many elements as a standard queue
B.
A sequence container that supports O(1) insertion and deletion at BOTH the front and back
C.
A queue with two independent thread locks
D.
A circular array that cannot be resized
Explanation & Key
Correct Answer:
26
How does a Min-Stack achieve getMin() in O(1) time without increasing push/pop time complexity?
A.
By sorting the stack after each push
B.
By maintaining an auxiliary stack that stores the minimum value seen so far alongside each element
C.
By using a balanced binary search tree
D.
By scanning the stack linearly on getMin()
Explanation & Key
Correct Answer:
27
What is the time complexity of solving the "Largest Rectangle in Histogram" problem using a Monotonic Stack?
A.
O(n^2)
B.
O(n log n)
C.
O(n)
D.
O(n^3)
Explanation & Key
Correct Answer:
28
In the Sliding Window Maximum problem of window size k over an array of size n, which data structure achieves optimal O(n) total time?
A.
Max-Heap (Priority Queue)
B.
Monotonic Deque storing indices in decreasing order of values
C.
Standard FIFO Queue
D.
Stack
Explanation & Key
Correct Answer:
29
What is the result of evaluating the postfix expression: `5 3 + 2 * 4 -`?
A.
12
B.
16
C.
8
D.
20
Explanation & Key
Correct Answer:
30
Why does recursion use the Call Stack instead of a Queue to track function invocations?
A.
Because the most recently called function must finish and return before the caller can resume (Last-In, First-Out)
B.
Because stacks use less memory than queues
C.
Because queues do not support integer local variables
D.
Because modern CPUs have hardware queues but no stack pointers
Explanation & Key
Correct Answer:
31
What is the time complexity of the Valid Parentheses string validation algorithm using a Stack?
A.
O(n^2)
B.
O(n)
C.
O(log n)
D.
O(1)
Explanation & Key
Correct Answer:
32
How can a Stack be implemented using a single FIFO Queue?
A.
Push enqueues the element, then rotates the previous n-1 elements to the back of the queue
B.
It is impossible with only one queue
C.
Reverse the queue after each pop
D.
Sort the queue descending
Explanation & Key
Correct Answer:
33
What is a monotonic stack's state when finding the "Previous Smaller Element"?
A.
Monotonically increasing (popping elements greater than or equal to current element)
B.
Monotonically decreasing
C.
Alternating positive and negative
D.
Strictly sorted descending
Explanation & Key
Correct Answer:
34
What causes the "Queue Full" condition in a linear array implementation of a queue even when slots at the front are empty?
A.
Underflow
B.
False Overflow (Rear reaches capacity - 1 while Front > 0 due to prior dequeues)
C.
Memory corruption
D.
Null pointer exception
Explanation & Key
Correct Answer:
35
In the Shunting-Yard algorithm (Dijkstra), what is used to convert an Infix expression to Postfix?
A.
An operator stack and an output queue
B.
Two queues
C.
A binary tree
D.
A hash table
Explanation & Key
Correct Answer:
36
What is the space complexity of an empty `std::stack` in C++ by default?
A.
O(1) allocating a default underlying deque container buffer
B.
O(n) allocating 10,000 slots
C.
0 bytes
D.
Requires malloc on construction
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong