0% found this document useful (0 votes)
30 views4 pages

Queue Questions - Data Structure

The document contains multiple-choice questions focused on queue data structures, covering topics such as queue behavior, operation complexity, C++ interface methods, and queue algorithms. It includes questions about array-based queue implementations, memory efficiency, and FIFO principles. Each question is followed by four answer options, testing knowledge of queue operations and characteristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Queue Questions - Data Structure

The document contains multiple-choice questions focused on queue data structures, covering topics such as queue behavior, operation complexity, C++ interface methods, and queue algorithms. It includes questions about array-based queue implementations, memory efficiency, and FIFO principles. Each question is followed by four answer options, testing knowledge of queue operations and characteristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Multiple-Choice Questions on Queue Data Structures

1. Queue Fundamental Behavior


Question: When implementing a queue with a fixed-size array, what
problem occurs when the rear pointer reaches the end of the array?
a) The front pointer automatically resets to 0.
b) New elements cannot be added unless the queue wraps around or
resizes.
c) The queue automatically converts to a stack.
d) The size counter resets to zero.

2. Queue Operation Complexity


Question: In the array-based queue implementation shown (with `first`,
`last`, and `size`), what is the time complexity of `pop()`?
a) O(n)
b) O(1)
c) O(log n)
d) O(size)

3. C++ Queue Interface


Question: Which C++ queue method returns the element at the back of
the queue?
a) `front()`
b) `peek()`
c) `get_last()`
d) `back()`

4. Queue State Analysis


Question: Given an array-based queue with `first=3`, `last=5`, and
`size=3` (array size=6), what happens after a `pop()` operation?
a) `first=4`, `size=2`
b) `first=4`, `size=2`, `last=5`
c) `first=3`, `size=2`
d) `first=0`, `size=2`

5. Code Output Prediction


Question: What is the output of this code?

a) 5 15
b) 10 15
c) 5 10
d) 15 15

6. Bounded Queue Limitation


Question: Why is a dynamic array preferred over a fixed array for queue
implementation?
a) To reduce memory usage.
b) To improve `front()` operation speed.
c) To support unlimited element additions.
d) To eliminate the need for `size` tracking.

7. Queue Reversal Algorithm


Question: To reverse a queue Q using a stack S and variable X, what is
the correct sequence?
a) 1. Move all Q elements to S. 2. Move all S elements back to Q.
b) 1. Move half of Q to S. 2. Swap remaining elements.
c) 1. Copy Q to S. 2. Pop S while pushing to Q.
d) Use X to store elements while swapping ends.

8. Queue Size Calculation


Question: In an array-based queue with `first=2`, `last=4`, and `size=3`
(array size=8), what is `size` after two `pop()` operations?
a) 0
b) 1
c) 2
d) 3

9. Boundary Condition Handling


Question: What "special behavior" is needed when the rear pointer
reaches the array end in a non-circular queue?
a) Resize array or block new insertions.
b) Move all elements to the array start.
c) Automatically convert to a circular queue.
d) Reset rear pointer to 0.

10. Queue Initialization


Question: After initializing a queue and executing `push(8)`, `push(2)`,
`pop()`, `push(5)`, what is the result of `front()`?
a) 8
b) 2
c) 5
d) NULL
11. Empty Queue Behavior
Question: What happens when `pop()` is called on an empty queue in
C++?
a) Returns 0.
b) Undefined behavior (typically crashes).
c) Returns a default-constructed value.
d) Automatically resizes the queue.

12. Memory Efficiency


Question: In the array-based implementation shown, why are `first`, `last`,
and `size` all tracked?
a) To reduce memory fragmentation.
b) To avoid expensive array-shifting during `pop()`.
c) To enable binary search.
d) To support random access.

13. Code Analysis


Question: What does this function do?
```cpp
void transform(queue<int>& q) {
stack<int> s;
while (!q.empty()) {
s.push(q.front());
q.pop();
}
while (!s.empty()) {
q.push(s.top());
s.pop();
}
}
```
a) Sorts the queue.
b) Reverses the queue.
c) Duplicates the queue.
d) Clears the queue.

14. FIFO Violation


Question: Which operation violates the FIFO principle of queues?
a) Adding elements to the rear.
b) Removing elements from the front.
c) Accessing the rear element during insertion.
d) Checking if the queue is empty.
Answer: c)
---

15. Queue State Transition


Question: Starting with `queue: [4,8,6]` (front=4, rear=6), what is the
state after `pop()` → `push(2)` → `pop()`?
a) [8,6]
b) [6,2]
c) [8,2]
d) [2]

You might also like