wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DS UNIT-2 TEST-3

Total questions: 10

Worksheet time: 23mins

Name
Class
Date
1.

Which of the following operations is performed more efficiently by doubly linked list than by linear linked list?

a)

Deleting a node whose location is given

b)

Searching an unsorted list for a given item

c)

Inserting a node after the node with a given location

d)


Traversing the list to process each node

2.

The minimum number of fields with each node of doubly linked list is

A) in a normal case

B) in an optimal way

a)

1 ,2

b)

2 ,3

c)

3, 2

d)

4, 4

3.

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?

a)

X->Bwd.Fwd = X->Fwd ; X.Fwd->Bwd = X->Bwd ;

b)

X.Bwd->Fwd = X.Bwd ; X->Fwd.Bwd = X.Bwd ;

c)

X->Bwd->Fwd = X->Bwd ; X->Fwd->Bwd = X->Fwd;

d)

X->Bwd->Fwd = X->Fwd; X->Fwd->Bwd = X->Bwd ;

4.

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?

a)


Add an element after the last element of the list

b)

Interchange the first two elements of the list

c)

Delete the first element of the list

d)

Delete the last element of the list

5.

See the image and answer the question

a)

It is not possible to reverse a singly linked list in O(1) space.

b)

The best algorithm for the problem takes 

theta(n logn)    

theta time in the worst case

c)

The best algorithm for the problem takes 

theta(n)    

theta time in the worst case

d)

The best algorithm for the problem takes theta(n^2)    

theta time in the worst case

6.

Correct Program to find Middle of a Linked list ?

a)

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)

b)

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)

7.

Which of the following problems can be solved using 2 pointers on linked list?

a)

Detecting cycle in a linked list

b)

Finding intersection of two linked lists

c)

Finding middle element of a linked list

8.

Which of the following is optimal to find an element at kth position at the linked list?

a)

Single Linked List

b)

Double Linked List

c)

Circular Linked List

d)

Array implementation of Linked List

9.

The type of pointer used to point to the address of the next element in a linked list?

a)

pointer to character

b)

pointer to integer

c)

pointer to node

d)

all of the above

10.

A linked list in which none of the nodes contains a NULL pointer is?

a)

Single Linked List

b)

Double Linked List

c)

Circular Single Linked List

d)

Circular Double Linked List