DS UNIT-2 TEST-2

DS UNIT-2 TEST-2

University

13 Qs

quiz-placeholder

Similar activities

Data Structures Activity - 1

Data Structures Activity - 1

University

15 Qs

Data Structures - Training: Quiz 1

Data Structures - Training: Quiz 1

University

11 Qs

Data structures

Data structures

University

12 Qs

M3-1

M3-1

University

15 Qs

Quiz - Linked list

Quiz - Linked list

University

14 Qs

User-Defined DS

User-Defined DS

University

15 Qs

Linked List (Chapter 2)

Linked List (Chapter 2)

University

15 Qs

Data Structures Quiz

Data Structures Quiz

University

10 Qs

DS UNIT-2 TEST-2

DS UNIT-2 TEST-2

Assessment

Quiz

Computers

University

Hard

Created by

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
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?