This set of Java Multiple Choice Questions & Answers on “Data Structures-Queue”.
1. Which of the below is not a subinterface of Queue? Answer: b 2. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined? Answer: a 3. PriorityQueue is thread safe. Answer: a 4. What is difference between dequeue() and peek() function of java? Answer: c 5. What is the difference between Queue and Stack? Answer: a 6. What are the use of front and rear pointers in CircularQueue implementation? Answer: c 7. What is the correct method used to insert and delete items from the queue? Answer: b 8. Which data structure is used in Breadth First Traversal of a graph? Answer: b 9. Where does a new element be inserted in linked list implementation of a queue? Answer: b 10. If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder to insert an element in the queue? Answer: b To practice all areas of Java, here is complete set on Multiple Choice Questions and Answers on Java.
a) BlockingQueue
b) BlockingEnque
c) TransferQueue
d) BlockingQueue
Clarification: BlockingQueue, TransferQueue and BlockingQueue are subinterfaces of Queue.
a) Integer.MAX_VALUE
b) BigDecimal.MAX_VALUE
c) 99999999
d) Integer.INFINITY
Clarification: A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE.
a) True
b) False
Clarification: PriorityQueue is not synchronized. BlockingPriorityQueue is the thread safe implementation.
a) dequeue() and peek() remove and return the next time in line
b) dequeue() and peek() return the next item in line
c) dequeue() removes and returns the next item in line while peek() returns the next item in line
d) peek() removes and returns the next item in line while dequeue() returns the next item in line
Clarification: dequeue() removes the item next in line. peek() returns the item without removing it from the queue.
a) Stack is LIFO; Queue is FIFO
b) Queue is LIFO; Stack is FIFO
c) Stack and Queue is FIFO
d) Stack and Queue is LIFO
Clarification: Stack is Last in First out (LIFO) and Queue is First in First out(FIFO).
a) Front pointer points to first element; rear pointer points to the last element
b) Rear pointer points to first element; front pointer points to the last element
c) Front and read pointers point to the first element
d) Front pointer points to the first element; rear pointer points to null object
Clarification: CircularQueue implementation is an abstract class where first and rear pointer point to the same object.
a) push and pop
b) enqueue and dequeue
c) enqueue and peek
d) add and remove
Clarification: enqueue is pushing item into queue; dequeue is removing item from queue; peek returns object without removing it from queue.
Stack uses push and pop methods. add and remove are used in the list.
a) Stack
b) Queue
c) Array
d) Tree
Clarification: In Breadth First Traversal of graph the nodes at the same level are accessed in the order of retrieval (i.e FIFO).
a) Head of list
b) Tail of list
c) At the centre of list
d) All the old entries are pushed and then the new element is inserted
Clarification: To maintain FIFO, newer elements are inserted to the tail of the list.
a) rear=(rear%1)+MAX_SIZE
b) rear=(rear+1)%MAX_SIZE
c) rear=rear+(1%MAX_SIZE)
d) rear=rear%(MAX_SIZE+1)
Clarification: The front and rear pointer od circular queue point to the first element.