Java Questions & Answers – Data Structures-Queue

This set of Java Multiple Choice Questions & Answers focuses on “Data Structures-Queue”.

1. Which of the below is not a subinterface of Queue?
a) BlockingQueue
b) BlockingEnque
c) TransferQueue
d) BlockingQueue
View Answer

Answer: b
Explanation: BlockingQueue, TransferQueue and BlockingQueue are subinterfaces of Queue.

2. What is the remaining capacity of BlockingQueue whose intrinsic capacity is not defined?
a) Integer.MAX_VALUE
b) BigDecimal.MAX_VALUE
c) 99999999
d) Integer.INFINITY
View Answer

Answer: a
Explanation: A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE.

3. PriorityQueue is thread safe.
a) True
b) False
View Answer

Answer: a
Explanation: PriorityQueue is not synchronized. BlockingPriorityQueue is the thread safe implementation.
advertisement
advertisement

4. What is difference between dequeue() and peek() function of java?
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
View Answer

Answer: c
Explanation: dequeue() removes the item next in line. peek() returns the item without removing it from the queue.

5. What is the difference between Queue and Stack?
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
View Answer

Answer: a
Explanation: Stack is Last in First out (LIFO) and Queue is First in First out(FIFO).
Note: Join free Sanfoundry classes at Telegram or Youtube

6. What are the use of front and rear pointers in CircularQueue implementation?
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
View Answer

Answer: c
Explanation: CircularQueue implementation is an abstract class where first and rear pointer point to the same object.

7. What is the correct method used to insert and delete items from the queue?
a) push and pop
b) enqueue and dequeue
c) enqueue and peek
d) add and remove
View Answer

Answer: b
Explanation: 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.
advertisement

8. Which data structure is used in Breadth First Traversal of a graph?
a) Stack
b) Queue
c) Array
d) Tree
View Answer

Answer: b
Explanation: In Breadth First Traversal of graph the nodes at the same level are accessed in the order of retrieval (i.e FIFO).

9. Where does a new element be inserted in linked list implementation of a queue?
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
View Answer

Answer: b
Explanation: To maintain FIFO, newer elements are inserted to the tail of the list.
advertisement

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?
a) rear=(rear%1)+MAX_SIZE
b) rear=(rear+1)%MAX_SIZE
c) rear=rear+(1%MAX_SIZE)
d) rear=rear%(MAX_SIZE+1)
View Answer

Answer: b
Explanation: The front and rear pointer od circular queue point to the first element.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java, here is complete set on 1000+ Multiple Choice Questions and Answers on Java.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.