# Double Ended Queue (Dequeue) | Data Structure MCQs

1.

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 cur = temp;
Object e = temp.getEle();
size--;
return e;
}
}```
B.)
```public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node cur = temp.getNext();
Object e = temp.getEle();
size--;
return e;
}
}```
C.)
```public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node cur = temp.getNext();
Object e = temp.getEle();
size--;
return e;
}
}```
D.) None of these

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’.

2.

After performing these set of operations, what does the final list look contain?

```InsertFront(10);
InsertFront(20);
InsertRear(30);
DeleteFront();
InsertRear(40);
InsertRear(10);
DeleteRear();
InsertRear(15);
display();```

A.) 10 30 10 15
B.) 20 30 40 15
C.) 20 30 40 10
D.) 10 30 40 15

A careful tracing of the given operation yields the result.
10
20 10
20 10 30
10 30
10 30 40
10 30 40 10
10 30 40
10 30 40 15

3.

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);
}
else
{
temp.setNext(cur);
}
size++;
}```
B.)
```public void function(Object item)
{
Node temp = new Node(item,null);
if(isEmpty())
{
temp.setNext(trail);
}
else
{
temp.setNext(cur);
}
size++;
}```
C.)
```public void function(Object item)
{
Node temp = new Node(item,null);
if(isEmpty())
{
temp.setNext(cur);
}
else
{
temp.setNext(trail);
}
size++;
}```
D.) None of these

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()).

4.

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 these

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

5.

What is the time complexity of deleting from the rear end of the dequeue implemented with a singly linked list?

A.) O(nlogn)
B.) O(logn)
C.) O(n)
D.) O(n2)