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
Create a free account and access millions of resources
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
14 questions
PAW-Quiz PPT Awal
Quiz
•
University
10 questions
Visual Basic 2010
Quiz
•
8th Grade - University
10 questions
Списки Python + Pygame
Quiz
•
KG - University
13 questions
Functional Programming
Quiz
•
University
15 questions
NSCC-CODE TO COIN
Quiz
•
University
14 questions
Binary Tree
Quiz
•
University
11 questions
Trees
Quiz
•
University
10 questions
Website Usability and UX
Quiz
•
University
Popular Resources on Wayground
10 questions
Honoring the Significance of Veterans Day
Interactive video
•
6th - 10th Grade
9 questions
FOREST Community of Caring
Lesson
•
1st - 5th Grade
10 questions
Exploring Veterans Day: Facts and Celebrations for Kids
Interactive video
•
6th - 10th Grade
19 questions
Veterans Day
Quiz
•
5th Grade
14 questions
General Technology Use Quiz
Quiz
•
8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Circuits, Light Energy, and Forces
Quiz
•
5th Grade
19 questions
Thanksgiving Trivia
Quiz
•
6th Grade
Discover more resources for Computers
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
9 questions
Principles of the United States Constitution
Interactive video
•
University
18 questions
Realidades 2 2A reflexivos
Quiz
•
7th Grade - University
10 questions
Dichotomous Key
Quiz
•
KG - University
25 questions
Integer Operations
Quiz
•
KG - University
7 questions
What Is Narrative Writing?
Interactive video
•
4th Grade - University
20 questions
SER vs ESTAR
Quiz
•
7th Grade - University
