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. A queue with insert/delete defined for front side of the queue
Answer: A
Explanation:
A dequeue or a double ended queue is a queue with insert/delete defined for both front and rear ends of the queue.
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); } else { Node cur = head.getNext(); temp.setNext(cur); head.setNext(temp); } size++; }
B.
public void function(Object item) { Node temp = new Node(item,null); if(isEmpty()) { temp.setNext(trail); head.setNext(trail); } else { Node cur = head.getNext(); temp.setNext(cur); head.setNext(temp); } size++; }
C.
Take Data Structure I Practice Tests - Chapterwise! Start the Test Now: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 public void function(Object item) { Node temp = new Node(item,null); if(isEmpty()) { Node cur = head.getNext(); temp.setNext(cur); head.setNext(temp); } else { temp.setNext(trail); head.setNext(temp); } size++; }
D.
public void function(Object item) { Node temp = new Node(item,null); if(isEmpty()) { Node cur = head.getNext(); temp.setNext(cur); cur.setNext(temp); } else { head.setNext(trail); trail.setNext(temp); } size++; }
Answer: A
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()).
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
Answer: B
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.
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
Answer: D
Explanation:
All of the mentioned can be implemented with a dequeue.
5. 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(); Node cur = temp; Object e = temp.getEle(); head.setNext(cur); size--; return e; } }
B.
public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = temp.getNext(); Object e = temp.getEle(); head.setNext(cur); size--; return e; } }
C.
public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = temp.getNext(); Object e = temp.getEle(); head.setNext(temp); size--; return e; } }
D.
public Object deleteFront() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = temp.getNext(); Object e = temp.getEle(); temp.setNext(cur); size--; return e; } }
Answer: B
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’.
6. Which of the following can be used to delete an element from the rear end of the queue?
A.
public Object deleteRear() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = temp; while(temp.getNext() != trail) { temp = temp.getNext(); cur = cur.getNext(); } Object e = temp.getEle(); cur.setNext(trail); size--; return e; } }
B.
public Object deleteRear() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = head; while(temp != trail) { temp = temp.getNext(); cur = cur.getNext(); } Object e = temp.getEle(); cur.setNext(trail); size--; return e; } }
C.
public Object deleteRear() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = head; while(temp.getNext()!=trail) { temp = temp.getNext(); cur = cur.getNext(); } Object e = temp.getEle(); cur.setNext(trail); size--; return e; } }
D.
public Object deleteRear() throws emptyDEQException { if(isEmpty()) throw new emptyDEQException("Empty"); else { Node temp = head.getNext(); Node cur = head; while(temp.getNext()!=trail) { temp = temp.getNext(); cur = cur.getNext(); } Object e = temp.getEle(); temp.setNext(trail); size--; return e; } }
Answer: C
Explanation:
Traverse till the end of the list with a pointer ‘temp’ and another ‘cur’ which is trailing behind temp, make ‘cur’ point to trail, this removes all reference for ‘temp’.
7. 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)
Answer: C
Explanation:
Since a singly linked list is used, first you have to traverse till the end, so the complexity is O(n).
8. 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
Answer: D
Explanation:
9. The essential condition which is checked before deletion in a linked queue is?
A. Underflow
B. Overflow
C. Front value
D. Rear value
Answer: A
Explanation:
To check whether there is element in the list or not.
10. Which of the following is true about linked list implementation of queue?
A. In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end
B. In push operation, if new nodes are inserted at the beginning, then in pop operation, nodes must be removed from the beginning
C. In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from end
D. In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from beginning
Answer: A
Explanation:
It can be done by both the methods.
- LATEST NEET MCQ’S ON Marasmus [10+ Q&A]
- EXAM NEET MCQs on Root Modifications [10+ ADDED]
- TOP NEET MCQ’S ON Parenchyma Cells
- Biodiversity [LATEST NEET MCQ’S FOR EXAM]
- MCQs on Slime Moulds [TOP 10+ SOLVED]
- TOP NEET MCQ’s On Semiconductor Diode [Physics]
- Alternating Current NEET MCQs [ EXAM Q&A ]
- Latest NEET MCQ’s on Alkene [TOP 10+ Solved]