# Data Structure Questions and Answers-Double Ended Queue (Dequeue)

## Click on any option to know the CORRECT ANSWERS

 Question 1
What is a dequeue?
 A A queue with insert/delete defined for both front and rear ends of the queue B A queue implemented with a doubly linked list C A queue implemented with both singly and doubly linked lists D None of the mentioned

Question 1 Explanation:
A dequeue or a double ended queue is a queue with insert/delete defined for both front and rear ends of the queue.

 Question 2
Select the function which performs insertion at the front end of the dequeue?
 A public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { temp.setNext(trail); head.setNext(temp B public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { temp.setNext(trail); head.setNext(trail< C public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { Node cur = head.getNext(); temp.setNext< D None of the mentioned

Question 2 Explanation:
Create a new node, if the current list is empty, the 'head' points to this node and this new node points to 'trail'. Otherwise, 'head' points to the new node and this in turn points to the current first element(head.getNext()).

 Question 3
What is the functionality of the following piece of code?

public void function(Object item) { 	Node temp=new Node(item, trail); 	if(isEmpty()) 	{ 		head.setNext(temp); 		temp.setNext(trail); 	} 	else 	{ 		Node cur=head.getNext(); 		while(cur.getNext()!=trail) 		{ 			cur=cur.getNext(); 		} 		cur.setNext(temp); 	} 	size++; }
 A Insert at the front end of the dequeue B Insert at the rear end of the dequeue C Fetch the element at the rear end of the dequeue D Fetch the element at the front end of the dequeue

Question 3 Explanation:
If the list is empty, this new node will point to 'trail' and will be pointed at by 'head'. Otherwise, traverse till the end of the list and insert the new node there.

 Question 4
What are the applications of dequeue?
 A A-Steal job scheduling algorithm B Can be used as both stack and queue C To find the maximum of all sub arrays of size k D All of the mentioned
 A public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext() B public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext() C public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext D None of the mentioned