# Link List Data Structure Mock Test – 1

 Question 1
The function DELETE(head, element) is used to delete a node from the linked list by finding the node value with a given element. The parameter head is the first node of the list. Find the missing statements XX and YY in the following "DELETE" function to delete the node?
(Assume all elements are distinct in the list and the function returns pointers that points to the first node of the list.)
``````Node DELETE (Node head, int element)
{
if(x.data==element )
while(x.next!=NULL)
{
if(_XX__)
{
__YY__
}
x=x.next;
}
} ``````
 A XX : x.data == elementYY : x.next = x.next.next B XX : x.next.data == elementYY : x.next = x.next.next C XX : x.data == elementYY : x.next.next = x.next D XX : x.next.data == elementYY : x.next.next = x.next
Data Structure
Question 1 Explanation:
Consider that we want to delete node with value 99. `````` if(x.next.data==99)   //XX
{
x.next=x.next.next;    //YY
} `````` Click to Join Our Telegram Group for Latest Update of MOCK TEST Question 2
Identify the functionality of the following code when function return the value 1.
("head" pointer point to the first node of the non-empty linked list)
`````` int find(Node *head)
{
{
}
while((P1!= NULL) && (P2!=NULL)
{
if (P1==P2) return 1;
P1=P1 -> next;
P2= (P2-> next !=NULL)?P2 -> next -> next:NULL;
}
return 0;
}
``````
 A It finds the duplicate element in the list. B It finds the middle node in th list. C It finds the cycle in the list. D It finds the last node in the lsit.
Data Structure
Question 2 Explanation:
P1 is slower pointer, which moves to the next node in every iteration of while loop.
P2 is faster pointer, which moves to the next to next node in every iteration.
If there exist a cycle in the linked list (non-empty), it return 1 by checking P1 == P2.
otherwise it return 0. Click to Join Our Telegram Group for Latest Update of MOCK TEST Question 3
Consider the following code:
``````Node * find (Node *head)
{
while(P2)
{
P1=P1-> next;
P2=(P2 -> next)?P2 -> next -> next:NUll;
}
printf("%d",P1 -> value);
}
``````
Assume Node is the structure type with two parameters : 'value' and 'next'. Identify the node printed by the above code if non-empty linked list header is passed to the function find?
 A Value of the first node of the list B Value of the second node of the list C Value of the middle node of the list D Value of the last node of the list
Data Structure
Question 3 Explanation:
P1 traverses node by node.
P2 traverses by skipping one node. The node pointed by P1 is the middle node in the linked list when P2 reaches to NULL.
Therefore, middle element of the list is printed by P1 -> value. Click to Join Our Telegram Group for Latest Update of MOCK TEST Question 4
Consider the following code which is used to detect the loop in the linked list. Find the missing statement X?
``````p=head;
while(X)
{
if(p==q) exit(0); //loop detected
p=p -> next;
q=(q -> next)?(q -> next -> next):q -> next;

} ``````
 A p != NULL B q != NULL C (p!=NULL) && (q!=NULL) D (p!=NULL) || (q!=NULL)
Data Structure
Question 4 Explanation:
Both p and q are not NULL then there is a loop in the linked list and it will be detected by slow pointer (p) and fast pointer (q).
Therefore, X: (p !=NULL) && (q != NULL) Click to Join Our Telegram Group for Latest Update of MOCK TEST   Click to Join Our Telegram Group for Latest Update of MOCK TEST 