1.
Assume a linked list has been created and the start pointer is referring the first node of that linked list. Select the following code that can add a new node that addresses hold by temp pointer, at beginning of that linked list.
Correct Answer
A. Temp->link=start; start=temp;
Explanation
The correct answer is "temp->link=start; start=temp;". This code first assigns the link of the new node to the start pointer, effectively making the new node point to the previous first node. Then, it assigns the start pointer to the new node, making the new node the first node of the linked list.
2.
Insertion of a node at the beginning of the singly linked list involves modification of?
Correct Answer
B. Two pointer
Explanation
When inserting a node at the beginning of a singly linked list, two pointers need to be modified. The first pointer is the new node's next pointer, which needs to point to the current first node of the list. The second pointer is the head pointer of the list, which needs to be updated to point to the new node, making it the new first node of the list. By modifying these two pointers, the new node is successfully inserted at the beginning of the linked list.
3.
Assume a linked list referred by start pointer. which of the following set of statements will result in the deletion of a node at position pos.
Correct Answer
A. If(pos==1)
start=start->link;
else
{
t1=start;
for(int i=2;ilink;
}
t1->link=t1->link->link;
}
Explanation
The given set of statements will result in the deletion of a node at position pos. If pos is equal to 1, then the start pointer is updated to point to the second node, effectively deleting the first node. Otherwise, a temporary pointer t1 is set to the start pointer, and a loop is executed until the desired position is reached. Inside the loop, t1 is updated to point to the previous node before the node to be deleted, and then the link of the previous node is updated to skip the node to be deleted. This effectively deletes the node at the specified position.
4.
Given a 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?
Correct Answer
A. Possible if size of linked list is even
Explanation
The given answer states that it is possible to delete the node X from the linked list if the size of the linked list is even. This means that if the number of nodes in the linked list is divisible by 2, we can delete the node X. However, if the size of the linked list is odd, we cannot delete the node X using this method. Additionally, the answer also suggests a two-step process to delete the node X if it is not the last node or the first node in the linked list.
5.
Which of the following points is/are true about Linked List data structure when it is compared with array
Correct Answer
D. All of the mentioned
Explanation
The given answer is correct because all of the mentioned points are true about the comparison between Linked List and array data structures. Arrays have better cache locality, meaning that accessing elements in an array is faster compared to accessing elements in a Linked List. It is indeed easier to insert and delete elements in a Linked List because it involves changing pointers, whereas in an array, elements need to be shifted. Lastly, random access is not allowed in a typical implementation of Linked Lists, meaning that to access an element, we need to traverse the list from the beginning.
6.
What is the output of following function for start pointing to first node of following linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start==NULL)
return;
while(start->link!=NULL)
{
printf("%d ",(start->link)->info);
start=start->link;
}
}
Correct Answer
B. 2 3 4 5 6
Explanation
The given function starts from the first node of the linked list and prints the info value of each node's next node until it reaches the last node. In this case, the output will be "2 3 4 5 6" because it starts from the first node (which has info value of 1) and prints the info value of each node's next node (2, 3, 4, 5, 6) until it reaches the last node.
7.
What is the change in the linked list after the execution of the following code?
start:- points to first node of linked
start->info=start->link->info;
Correct Answer
A. The values of first node and second node will be same
Explanation
After the execution of the given code, the value of the first node in the linked list will be copied into the second node. Therefore, the values of the first node and second node will be the same.
8.
Linked is a ......
Correct Answer
A. Linear data structure
Explanation
The given correct answer is "Linear data structure." A linear data structure is a type of data structure where elements are arranged in a sequential manner, with each element having a unique predecessor and successor, except for the first and last elements. Examples of linear data structures include arrays, linked lists, stacks, and queues. In contrast, non-linear data structures, such as trees and graphs, do not have a sequential arrangement. Dynamic data structure refers to a data structure that can change in size during runtime, which is not mentioned in the question.
9.
You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list?
Correct Answer
C. Delete the last element of the list
Explanation
The operation of deleting the last element of the list is dependent on the length of the linked list. This is because in order to delete the last element, we need to traverse the entire list until we reach the second-to-last node and update its next pointer to null. The length of the list determines the number of nodes we need to traverse in order to reach the second-to-last node.
10.
Binary search is possible in Linked list.
Correct Answer
B. False
Explanation
Binary search is not possible in a linked list because unlike an array, a linked list does not provide constant time access to elements based on their index. In a linked list, elements are accessed sequentially by following the links between nodes. Binary search relies on random access to elements, which is not supported by a linked list. Therefore, it is not possible to perform binary search efficiently in a linked list.