DS UNIT-2 TEST-2
Quiz
•
Computers
•
University
•
Hard
PRASHANT ATMAKURI
Used 2+ times
FREE Resource
13 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
What are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8.
O(1) and O(n)
O(1) and O(1)
O(n) and O(1)
O(n) and O(n)
Answer explanation
Finding the 8th element from the beginning of a singly linked list requires traversing the first 8 nodes of the list, which takes O(8) time, or simply O(1) time since it's a constant time operation.
Finding the 8th element from the end of a singly linked list requires traversing the list until we reach the 8th node from the end. One way to do this is to first traverse the list once to determine its length, and then traverse the list again until we reach the node at position n-8. This takes O(n) time for the first traversal, and then O(n-8) time for the second traversal. Therefore, the time complexity of finding the 8th element from the end of a singly linked list is O(n).
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Is it possible to create a doubly linked list using only one pointer with every node.
Not Possible
Yes, possible by storing XOR of current node and next node
Yes, possible by storing XOR of addresses of previous and next nodes
Yes, possible by storing XOR of current node and previous node
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not given, can we delete the node X from given linked list?
Possible if X is not last node. Use following two steps (a) Copy the data of next of X to X. (b)Update the pointer of node X to the node after the next node. Delete next of X.
Possible if size of linked list is even
Possible if size of linked list is odd
Possible if X is not first node. Use following two steps (a) Copy the data of next of X to X. (b) Delete next of X.
Answer explanation
struct node *temp = X->next;
X->data = temp->data;
X->next = temp->next;
free(temp);
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which of the following is an application of XOR-linked lists?
Implementing stacks
Caching data structures
Memory-efficient linked list representation
Implementing queues
Answer explanation
XOR linked lists are a memory-efficient representation of linked lists. They store the XOR combination of the addresses of the previous and next nodes, reducing the memory overhead compared to traditional linked lists.
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following function to traverse a linked list.
void traverse(struct Node *head)
{
while (head->next != NULL)
{
printf("%d ", head->data);
head = head->next;
}
}
Which of the following is FALSE about above function?
The function is implemented incorrectly because it changes head
The function doesn't print the last node when the linked list is not empty
The function may crash when the linked list is empty
None of the Above
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node Q from the list?
O(log n)
O(1)
O(n)
O(log2 n)
Answer explanation
To delete a node Q from a singly linked list, we need to modify the next pointer of the node that precedes Q to point to the node that follows Q. However, in a singly linked list, we cannot traverse the list backwards from a given node, so we need to start from the beginning of the list to find the node that precedes Q.
Therefore, the worst-case time complexity of the best known algorithm to delete the node Q from the list is O(n), where n is the length of the list. This is because we may need to traverse the entire list to find the node that precedes Q.
However, if we have a pointer to the node that precedes Q, the deletion operation can be performed in O(1) time complexity, since we can simply modify the next pointer of that node to skip over Q. But, if we do not have a pointer to the node that precedes Q, we need to start from the beginning of the list and traverse the list to find it, which takes O(n) time complexity in the worst case.
7.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key What is the time complexity of all these operations put together?
O(Log2N)
O(N Log N)
O(N)
Θ(N2 Log N)
Answer explanation
The time complexity of all these operations put together is O(N log N).
The delete operation takes Θ(N) time because we need to traverse the list to find the record to be deleted.
The insert and find operations take O(log N) time each because the list is sorted and we can use binary search to locate the correct position for the new record or to find an existing record.
The decrease-key operation takes Θ(N) time because we need to traverse the list to find the record on which the operation is to be performed.
Assuming that there are M total operations (M = Θ(N) + O(log N) + O(log N) + Θ(N) = O(N)), the total time complexity of all operations is O(M log N) = O(N log N), because the operations take varying amounts of time but they are all performed on a list of size N.
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
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
18 questions
CIS2303 Week 4_5 Ch_3
Quiz
•
University
10 questions
INTO Artificial Intelligence
Quiz
•
University - Professi...
14 questions
ITF Chapter 1 Computing Devices
Quiz
•
University
10 questions
Machine Learning (Introduction)
Quiz
•
University
11 questions
Determining System Requirements
Quiz
•
University
15 questions
1.1.1 The structure and function of the processor
Quiz
•
11th Grade - University
10 questions
Planning and Implementation of Information Security
Quiz
•
University
10 questions
Programming in C
Quiz
•
University
Popular Resources on Wayground
20 questions
Halloween Trivia
Quiz
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Order of Operations
Quiz
•
5th Grade
20 questions
Halloween
Quiz
•
5th Grade
16 questions
Halloween
Quiz
•
3rd Grade
12 questions
It's The Great Pumpkin Charlie Brown
Quiz
•
1st - 5th Grade
20 questions
Possessive Nouns
Quiz
•
5th Grade
10 questions
Halloween Traditions and Origins
Interactive video
•
5th - 10th Grade
Discover more resources for Computers
10 questions
Halloween Movies Trivia
Quiz
•
5th Grade - University
12 questions
Halloween
Quiz
•
3rd Grade - University
5 questions
Using Context Clues
Interactive video
•
4th Grade - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
14 questions
Eat Healthy,Be Healty
Quiz
•
4th Grade - University
7 questions
History of Halloween: Pagan or Christian?
Interactive video
•
11th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
