Question 1
Find the functionality of the given code-
void function(int data)
{
int flag = 0;
if (head != null) {
Node temp = head.getNext();
while ((temp != head)
&& (!(temp.getItem() == data))) {
temp = temp.getNext();
flag = 1;
break;
}
}
if (flag)
System.out.println("success");
else
System.out.println("fail");
}
Question 2
What is the time complexity of searching for an element in a circular linked list?
Question 4
What is the functionality of the following code? Choose the most appropriate answer.
int function()
{
if (head == null)
return Integer.MIN_VALUE;
int var;
Node temp = head;
while (temp.getNext() != head)
temp = temp.getNext();
if (temp == head) {
var = head.getItem();
head = null;
return var;
}
temp.setNext(head.getNext());
var = head.getItem();
head = head.getNext();
return var;
}
Question 5
Consider a small circular linked list. How to detect the presence of cycles in this list effectively?
Question 9
Consider the below program, and identify which Operation is performed.
int solve(struct Node* head)
{
if (head == NULL)
return 1;
struct Node* ptr;
ptr = head->next;
while (ptr != NULL && ptr != head)
ptr = ptr->next;
return (ptr == head);
}
Question 10
Which of the following Statement is correct about Circular Linked List?
P1: Every Node has a successor.
P2: TIme complexity for deleting the first node is O(N).
P3: Last Node points to the NULL.
P4: Every Node contains the data and a next pointer to traverse the list.
There are 10 questions to complete.