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

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

 Question 1 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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
Question 4 Explanation:
All of the mentioned can be implemented with a dequeue.

 Question 5 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Which of the following can be used to delete an element from the front end of the queue?
 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
Question 5 Explanation:
Have two pointers, one(temp) pointing to the first element and the other(cur) pointing to the second element. Make the 'head' point to the second element, this removes all reference for 'temp'.

There are 5 questions to complete.