QUEUE
QUEUE
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the
other end (rear) is known as _____________
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
Explanation: Linear list of elements in which deletion is done at front side and insertion at rear side is called Queue. In
stack we will delete the last entered element first.
2. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
Answer: c
Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices which are
unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent vertex list will be considered to
add further unvisited vertices of the graph. To get the first unvisited vertex we need to follows First In First Out principle.
Queue uses FIFO principle.
c) Ordered array
d) Linear tree
Answer: a
Explanation: Element first added in queue will be deleted first which is FIFO principle.
4. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
Explanation: Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position
is connected back to the first position to make a circle. It forms a ring structure.
5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order will they be
removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: a
Explanation: Queue follows FIFO approach. i.e. First in First Out Approach. So, the order of removal elements are
ABCD.
6. A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we will follow first in first out
principle for insertion and deletion of elements. Element with least priority will be deleted in a priority queue
7. A normal queue, if implemented using an array of size MAX_SIZE, gets full when?
a) Rear = MAX_SIZE – 1
c) Front = rear + 1
d) Rear = front
Answer: a
Explanation: When Rear = MAX_SIZE – 1, there will be no space left for the elements to be added in queue. Thus queue
becomes full.
8. Queues serve major role in ______________
a) Simulation of recursion
Answer: c
Explanation: Simulation of recursion uses stack data structure. Simulation of arbitrary linked lists uses linked lists.
Simulation of resource allocation uses queue as first entered data needs to be given first priority during resource
allocation. Simulation of heap sort uses heap data structure.
a) Ordinary queue
c) Circular queue
d) Priority queue
Answer: b
Explanation: Queue always has two ends. So, single ended queue is not the type of queue.
Answer: d
Explanation: Array elements can be accessed in two steps. First, multiply the size of the data type with the specified
position, second, add this value to the base address. Both of these operations can be done in constant time, hence
accessing elements at a given index/position is faster
11. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack
Answer: d
Explanation: For every opening brace, push it into the stack, and for every closing brace, pop it off the stack. Do not
take action for any other character. In the end, if the stack is empty, then the input has balanced parentheses.
Answer: c
Explanation: Use one queue and one counter to count the number of elements in the queue.
13. Which of the following properties is associated with a queue?
a) First In Last Out
b) First In First Out
c) Last In First Out
d) Last In Last Out
Answer: b
Explanation: Queue follows First In First Out structure.
14. In a circular queue, how do you increment the rear end of the queue?
a) rear++
b) (rear+1) % CAPACITY
c) (rear % CAPACITY)+1
d) rear–
Answer: b
Explanation: Ensures rear takes the values from 0 to (CAPACITY-1).
15. What is the term for inserting into a full queue known as?
a) overflow
b) underflow
c) null pointer exception
d) program won’t be compiled
Answer: a
Explanation: Just as stack, inserting into a full queue is termed overflow.
Answer: d
Explanation: Enqueue operation is at the rear end, it takes O(1) time to insert a new item into the queue.
Answer: a
Explanation: In a linear queue, dequeue operation causes the starting elements of the array to be empty, and there is
no way you can use that space, while in a circular queue, you can effectively use that space. Priority queue is used to
delete the elements based on their priority. Higher priority elements will be deleted first whereas lower priority
elements will be deleted next. Queue data structure always follows FIFO principle.
23. If the MAX_SIZE is the size of the array used in the implementation of circular queue. How is rear
manipulated while inserting an element in the queue?
a) rear=(rear%1)+MAX_SIZE
b) rear=rear%(MAX_SIZE+1)
c) rear=(rear+1)%MAX_SIZE
d) rear=rear+(1%MAX_SIZE)
ANSWER: c) rear=(rear+1)%MAX_SIZE
24. A circular queue is implemented using an array of size 10. The array index starts with 0, front is 6, and rear
is 9. The insertion of next element takes place at the array index.
a) 0
b) 7
c) 9
d) 10
ANSWER: a) 0