Data Structure Questions and Answers-Doubly Linked List

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Doubly Linked List

Question 1
Which of the following is false about a doubly linked list?
A
We can navigate in both the directions
B
It requires more space than a singly linked list
C
The insertion and deletion of a node take a bit longer
D
None of the mentioned
Current affairs Questions answers
Question 1 Explanation: 
A doubly linked list has two pointers 'left' and 'right' which enable it to traverse in either direction. Compared to singly liked list which has only a 'next' pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion requires manipulation of two pointers, hence it takes a bit longer time.

Question 2
Given the Node class implementation, select one of the following that correctly inserts a node at the tail of the list.

public class Node { 	protected int data; 	protected Node prev; 	protected Node next; 	public Node(int data) 	{ 		this.data = data; 		prev = null; 		next = null; 	} 	public Node(int data, Node prev, Node next) 	{ 		this.data = data; 		this.prev = prev; 		this.next = next; 	} 	public int getData() 	{ 		return data; 	} 	public void setData(int data) 	{ 		this.data = data; 	} 	public Node getPrev() 	{ 		return prev; 	} 	public void setPrev(Node prev) 	{ 		this.prev = prev; 	} 	public Node getNext 	{ 		return next; 	} 	public void setNext(Node next) 	{ 		this.next = next; 	} } public class DLL { 	protected Node head; 	protected Node tail; 	int length; 	public DLL() 	{ 		head = new Node(Integer.MIN....VALUE, null, null); 		tail = new Node(Integer.MIN....VALUE, null, null); 		head.setNext(tail); 		length = 0; 	} }
A

public void insertRear(int data) { 	Node node = new Node(data, tail.getPrev(), tail); 	node.getPrev().setNext(node); 	tail.setPrev(node)
B

public void insertRear(int data) { 	Node node = new Node(data, tail.getPrev(), tail); 	node.getPrev().getPrev().setNext(node); 	tail
C

public void insertRear(int data) { 	Node node = new Node(data, tail.getPrev(), tail); 	node.getPrev().setNext(tail); 	tail.setPrev(node)
D

public void insertRear(int data) { 	Node node = new Node(data, head, tail); 	node.getPrev().setNext(node); 	tail.setPrev(node); 	length++; 
Home science Questions answers
Question 2 Explanation: 
First create a new node whose 'prev' points to the node pointed to by the 'prev' of tail. The 'next' of the new node should point to tail. Set the 'prev' of tail to point to new node and the 'prev' of new node to point to the new node.

Question 3
What is a memory efficient double linked list?
A
Each node has only one pointer to traverse the list back and forth
B
The list has breakpoints for faster traversal
C
An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list
D
None of the mentioned
Visual arts Questions answers
Question 3 Explanation: 
Memory efficient doubly linked list has been proposed recently which has only one pointer to traverse the list back and forth. The implementation is based on pointer difference.

Question 4
Which of the following piece of code removes the node from a given position?
A

public void remove(int pos) { 	if(pos<0 || pos>=size) 	{ 		System.out.println("Invalid position"); 		return; 	} 	
B

public void remove(int pos) { 	if(pos<0 || pos>=size) 	{ 		System.out.println("Invalid position"); 		return; 	} 	
C

public void remove(int pos) { 	if(pos<0 || pos>=size) 	{ 		System.out.println("Invalid position"); 		return
D
None of the mentioned
GK Questions answers
Question 4 Explanation: 
If the position to be deleted is not the head, advance to the given position and manipulate the previous and next pointers of next and previous nodes respectively.

Question 5
How do you calculate the pointer difference in a memory efficient double linked list?
A
head xor tail
B
pointer to previous node xor pointer to next node
C
pointer to previous node - pointer to next node
D
pointer to next node - pointer to previous node
Public administration Questions answers
Question 5 Explanation: 
The pointer difference is calculated using option b.

There are 5 questions to complete.

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<