WorksheetsDS UNIT-2 TEST-3
Total questions: 10
Worksheet time: 23mins
Which of the following operations is performed more efficiently by doubly linked list than by linear linked list?
Deleting a node whose location is given
Searching an unsorted list for a given item
Inserting a node after the node with a given location
Traversing the list to process each node
The minimum number of fields with each node of doubly linked list is
A) in a normal case
B) in an optimal way
1 ,2
2 ,3
3, 2
4, 4
A doubly linked list is declared as
struct Node {
int Value;
struct Node Fwd;
struct Node Bwd; );
Where Fwd and Bwd represent forward and backward link to the adjacent elements of the list. Which of the following segments of code deletes the node pointed to by X from the doubly linked list, if it is assumed that X points to neither the first nor the last node of the list?
X->Bwd.Fwd = X->Fwd ; X.Fwd->Bwd = X->Bwd ;
X.Bwd->Fwd = X.Bwd ; X->Fwd.Bwd = X.Bwd ;
X->Bwd->Fwd = X->Bwd ; X->Fwd->Bwd = X->Fwd;
X->Bwd->Fwd = X->Fwd; X->Fwd->Bwd = X->Bwd ;
Consider a singly linked list of the form where F is a pointer to the first element in the linked list and L is the pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
Add an element after the last element of the list
Interchange the first two elements of the list
Delete the first element of the list
Delete the last element of the list
See the image and answer the question
It is not possible to reverse a singly linked list in O(1) space.
The best algorithm for the problem takes
theta(n logn)
theta time in the worst case
The best algorithm for the problem takes
theta(n)
theta time in the worst case
The best algorithm for the problem takes theta(n^2)
theta time in the worst case
Correct Program to find Middle of a Linked list ?
class Node:
def init(self, k):
self.data = k
self.next = None
def printList(head):
curr = head
while curr != None:
print(curr.data)
curr = curr.next
print()
def printMiddle(ptr):
if head == None:
return
count = 0
curr = head
while curr :
curr = curr.next
count+=1
curr = head
for i in range (count//2):
curr = curr.next
print(curr.data)
head = Node(10)
head.next = Node(10)
head.next.next = Node(20)
printList(head)
printMiddle(head)
class Node:
def init(self, k):
self.data = k
self.next = None
def printList(head):
curr = head
while curr != None:
print(curr.data)
curr = curr.next
print()
def printMiddle(ptr):
if head == None:
return
count = 0
curr = head
while curr :
curr != curr.next
count+=1
curr = head
for i in range (count//2):
curr = curr.next
print(curr.data)
head = Node(10)
head.next = Node(10)
head.next.next = Node(20)
printList(head)
printMiddle(head)
Which of the following problems can be solved using 2 pointers on linked list?
Detecting cycle in a linked list
Finding intersection of two linked lists
Finding middle element of a linked list
Which of the following is optimal to find an element at kth position at the linked list?
Single Linked List
Double Linked List
Circular Linked List
Array implementation of Linked List
The type of pointer used to point to the address of the next element in a linked list?
pointer to character
pointer to integer
pointer to node
all of the above
A linked list in which none of the nodes contains a NULL pointer is?
Single Linked List
Double Linked List
Circular Single Linked List
Circular Double Linked List
