# YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

## 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 queue with insert/delete defined for both front and rear ends of the queue | |

A queue implemented with a doubly linked list | |

A queue implemented with both singly and doubly linked lists | |

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?

public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { temp.setNext(trail); head.setNext(temp | |

public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { temp.setNext(trail); head.setNext(trail< | |

public void function(Object item) { Node temp = new Node(item, null); if(isEmpty()) { Node cur = head.getNext(); temp.setNext< | |

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++; }

Insert at the front end of the dequeue | |

Insert at the rear end of the dequeue | |

Fetch the element at the rear end of the dequeue | |

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-Steal job scheduling algorithm | |

Can be used as both stack and queue | |

To find the maximum of all sub arrays of size k | |

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?

public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext() | |

public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext() | |

public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext | |

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.