Sample questions
Question 1Medium
I have implemented the queue with a linked list, keeping track of a front node and a rear node with two reference variables. Which of these reference variables will change during an insertion into a NONEMPTY queue?
- Neither changes
- Only front changes
- Only rear changes
- Both change
Answer: C. Only rear changes
Explanation
As the queue is non empty and there is rear pointer pointing, this only must be incremented.
Step-by-step solution
- Insertion adds a new node at the rear of the queue.
- Rear pointer points to the last node, so it moves to the new node.
- Front pointer remains pointing to the first node in the queue.
- Only the rear reference variable updates during insertion.
- Final answer: Only rear changes.
Why the other options are wrong
- A. Both front and rear change in empty queues, not non-empty.
- B. Front never changes during insertion in a queue.
- D. Only rear changes, front stays the same in non-empty queue.
Tip: Remember: Insertion in non-empty queue only affects rear pointer.
Question 2Medium
In a circular queue the value of r will be ..
- r=r+1
- r=(r+1)% [QUEUE_SIZE-1]
- r=(r+1)% QUEUE_SIZE
- r=(r-1)% QUEUE_SIZE
Answer: C. r=(r+1)% QUEUE_SIZE
Explanation
To insert the item at the rear pointer r is incremented by 1.Two statements can be used r=r+ Two statements can be used r=r+1; or r=(r+ ; or r=(r+1) %QUEUE SIZE ) %QUEUE_SIZE.
In case of circular queue, we use second statement for incrementing rear value i.e, for inserting element.
Step-by-step solution
- In a circular queue the index wraps back to the start after the last slot.
- Adding 1 to r and taking the remainder after QUEUE_SIZE wraps it to 0 after the last index.
- So r = (r+1) % QUEUE_SIZE.
Why the other options are wrong
- A. Plain r = r+1 runs past the end of the array. It does not wrap.
- B. Using QUEUE_SIZE-1 wraps one slot too early.
- D. Subtracting 1 moves the index backwards, not forwards.
Tip: Use (r+1) % size for a circular queue, for both front and rear pointers.
Question 3Medium
The initial configuration of the queue is a,b,c,d (a is the front end). To get the configuration d,c,b,a one needs a minimum of?
- 2 deletions and 3 additions
- 3 additions and 2 deletions
- 3 deletions and 3 additions
- 3 deletions and 4 additions
Answer: C. 3 deletions and 3 additions
Explanation
d must become the front item, so a, b and c must each be removed from the front: 3 deletions. Then c, b and a are added to the back in that order: 3 additions. This gives d, c, b, a.
Step-by-step solution
- A queue is FIFO, so only the front item can be removed.
- A, b and c must leave the front before d can be at the front.
- Deleting a, b and c takes 3 deletions and leaves d alone.
- Adding c, b and a behind d takes 3 additions, giving d, c, b, a.
- So the answer is 3 deletions and 3 additions: option C.
Why the other options are wrong
- A. Only 2 deletions leave c at the front, so d cannot be first; 2 deletions is too few.
- B. With 2 deletions, c is still in front of d, so the order cannot be reached.
- D. 3 deletions and 4 additions is more than needed; 3 additions are enough.
Tip: In a FIFO queue, to bring an item to the front you delete everything ahead of it, then re-add those items.
Question 4Medium
A ... is a linear list in which insertions and deletions are made to from either end of the structure.
- circular queue
- random of queue
- priority
- dequeue
Answer: D. dequeue
Explanation
A dequeue, also known as a double-ended queue, is an ordered collection of items similar to the queue. It has two ends, a front and a rear, and the items remain positioned in the collection. What makes a dequeue different is the unrestrictive nature of adding and removing items. New items can be added at either the front or the rear. Likewise, existing items can be removed from either end. In a sense, this hybrid linear structure provides all the capabilities of stacks and queues in a single data structure.
Step-by-step solution
- A list that allows insertion and deletion at both ends is a double-ended queue.
- It is called a deque (dequeue).
- So option D is correct.
Why the other options are wrong
- A. A circular queue reuses space but works at one end for each action.
- B. There is no standard structure called 'random of queue'.
- C. A priority queue removes by priority, not from either end.
Tip: Deque means double-ended queue.
Question 5Medium
The data structure which allows the insertion at both the ends, but allows the deletion at only one end is __
- Output restricted Deque
- Input restricted Deque
- Circular queue
- Linear queue
Answer: A. Output restricted Deque
Explanation
Because in Deque insertion and deletion can take place at any end, but in the question it is given as deletion is allowed only at one end. Hence it is Output restricted Deque.
Step-by-step solution
- Insertion happens at both ends.
- Deletion happens only at one end.
- This matches the definition of an output restricted deque.
- Output restricted deque allows insertion at both ends but deletion only at one end.
- The correct answer is Output restricted Deque.
Why the other options are wrong
- B. Input restricted deque allows deletion at both ends.
- C. Circular queue allows insertion and deletion at both ends.
- D. Linear queue allows insertion and deletion only at one end.
Tip: Remember: Output restricted deque allows insertion at both ends but deletion only at one end.
Question 6Medium
---is not the operation that can be performed on queue.
- Insertion
- Deletion
- Retrieval
- Traversal
Answer: D. Traversal
Explanation
The standard queue operations are insertion (enqueue), deletion (dequeue) and retrieval (reading the front item). Traversal, visiting every item in turn, is not a standard queue operation.
Step-by-step solution
- The main queue operations are insertion (enqueue), deletion (dequeue) and retrieval of the front item.
- Traversal, going through every element, is not a standard queue operation.
- Marked answer: Traversal (option D).
Why the other options are wrong
- A. Insertion is a standard queue operation.
- B. Deletion is a standard queue operation.
- C. Retrieval of the front item is a standard queue operation.
Tip: Queue core operations: enqueue, dequeue, front.
Question 7Medium
In a queue, the initial values of front pointer f rare pointer r should be ....... and ......respectively.
- 0 and 1
- 0 and -1
- -1 and 0
- 1 and 0
Answer: B. 0 and -1
Explanation
In a queue, the initial values of front pointer f rare pointer r should be 0 and -1 respectively.
Step-by-step solution
- Front starts at 0 as no elements are present.
- Rear is -1 because it's not pointing to any element initially.
- Queue is empty, so front and rear must be different.
- Correct values are 0 for front and -1 for rear.
- Final answer: 0 and -1.
Why the other options are wrong
- A. Rear should be -1, not 1.
- C. Front should be 0, not -1.
- D. Rear should be -1, not 0.
Question 8Medium
Which of the following is not the type of queue?
- Ordinary queue
- Single ended queue
- Circular queue
- Priority queue
Answer: B. Single ended queue
Explanation
A single-ended queue is not a standard type of queue. Queues typically have two ends, with operations at both the front and rear. A single-ended queue does not support operations at both ends, making it incorrect as a type of queue.
Step-by-step solution
- A queue has two ends: front and rear.
- Single ended queue has only one end, which is invalid.
- Ordinary, circular and priority queues have both ends.
- So single ended queue is not a type of queue.
Why the other options are wrong
- A. Ordinary queue is a valid type of queue.
- C. Circular queue is a valid type of queue.
- D. Priority queue is a valid type of queue.
Question 9Medium
One has implemented the queue with a circular array, keeping track of first, last, and count (the number of items in the array). Suppose first is zero, and last is SIZE-1. What can you tell me about count?
- count must be zero
- count must be SIZE
- count could be zero or SIZE, but no other values could occur
- count must be SIZE+1
Answer: C. count could be zero or SIZE, but no other values could occur
Explanation
This is the case where either the list is full or the list the made empty after it was full.
Step-by-step solution
- First is 0 and last is SIZE-1, so the used slots run across the whole array.
- If the queue holds items, they fill all SIZE slots, so count = SIZE.
- If it is empty after having been full, count = 0.
- So count can only be 0 or SIZE, and the correct answer is C (count could be zero or SIZE, but no other values could occur).
Why the other options are wrong
- A. Count can also be SIZE when the queue is full.
- B. Count can also be 0 when the queue is empty after being full.
- D. Count can never be SIZE+1 in an array of SIZE slots.
Tip: In a circular queue, first=0 and last=SIZE-1 means the array is either full or empty; count tells which.
Question 10Medium
A "queue" is also known as what?
- A FIFO
- A stack
- A LIFO
- A Linked List
Answer: A. A FIFO
Explanation
As the Stack behaves in Last In First Out manner.
Queue is a container or linear list in which items are added at one end and removed from the other end It is based on the principle end and removed from the other end. It is based on the principle of FIFO.
Step-by-step solution
- Queue adds items at one end and removes from the other.
- This follows First In First Out order.
- FIFO stands for First In First Out.
- So queue is also known as a FIFO.
Why the other options are wrong
- B. Stack behaves in Last In First Out manner.
- C. LIFO is the opposite of FIFO.
- D. Linked List is a data structure, not a queue type.
Practise all 13 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →