DS UNIT-2 TEST-3
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
PRASHANT ATMAKURI
Used 3+ times
FREE Resource
Enhance your content in a minute
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
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
Answer explanation
Doubly linked lists have a few advantages over linear linked lists when it comes to certain operations. Specifically, the following operation is performed more efficiently by a doubly linked list than by a linear linked list
Deleting a node given a pointer to the node.
In a linear linked list, deleting a node requires traversing the list to find the node to be deleted and its predecessor. Once these nodes have been found, the predecessor's next pointer is updated to skip over the node to be deleted. This operation takes O(n) time in the worst case, where n is the number of nodes in the list.
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
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
Answer explanation
In general, each node of doubly link list always has 3 fields, i.e., the previous node pointer, the data field, and the next node pointer, see - doubly linked list introduction So, answer should be option (C) 3. However, each node of doubly linked list can have only 2 fields, i.e., XOR pointer field, and data field. This XOR pointer field can points both previous node and next node, this is the best case with data field. This is called as memory efficient doubly linked list, see - XOR linked list – a memory efficient doubly linked list | set 1 Also, if we remove data node from the XOR linked list, then each node of this doubly linked list can have only 1 field, i.e., XOR pointer field. But, this is without data field so, this doubly linked list does not make sense.
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
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 ;
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
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
Answer explanation
Interchange the first two elements of the list: To interchange the first two elements of the list, we can simply update the head pointer of the list to point to the second element and update the next pointer of the second element to point to the first element. This can be done in constant time, regardless of the length of the list.
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
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
6.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
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)
7.
MULTIPLE SELECT QUESTION
2 mins • 1 pt
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
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
10 questions
ML Course Activity-II
Quiz
•
University
10 questions
Tes Awal Modul 5 CC
Quiz
•
University
14 questions
Sorting Algorithms
Quiz
•
University
15 questions
untitled
Quiz
•
11th Grade - University
13 questions
G Suite
Quiz
•
4th Grade - Professio...
10 questions
Quiz on Machine Thinking
Quiz
•
University
10 questions
Module 09 - Day 3
Quiz
•
University
10 questions
TOOLS FOR AD & TECHNOLOGY DEVELOPMENT (W4-W6)
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
