# Search Interview Questions

More than 3000 questions in repository.
There are more than 900 unanswered questions.
Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

Algorithm - Interview Questions and Answers for 'Cyclic linkedlist' - 1 question(s) found - Order By Newest

 Q1. Write code to see if a Linked List has cycle in it ? or Write code using Floyd Algorithm to see if a linked list has cycle in it ? What is it's comlexity ? Algorithm

Node start = null;

class Node {
Integer body;
Node nextNode;

Node(Integer value) {
body = value;
}
}

public static void main(String[] args) {

ll.traverse();

if(checkIfLoop(l1)){
System.out.println("There is a Loop");
} else {
System.out.println("No Loop");
}
}

private boolean checkifLoop(Test l1) {
Node slow = start;
Node fast = start;
Node faster = start;

while(slow != null ) {
fast = slow.nextNode;
faster = fast.nextNode;
if(slow == fast || slow == faster) {
return true;
}
slow = slow.nextNode;
}

return false;
}

}

Complexity of this algorithm is O(n)

Help us improve. Please let us know the company, where you were asked this question :

Related Questions

What is the difference between ArrayList and LinkedList ?
If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ?
In a Linked list with sorted numbers, insert a new numbers while maintaining the sort order.
Is this a valid initialization ? Explain.

Difference between ArrayList and LinkedList ?
Find the third last element in a linked list ?
Write a program for LinkedList, with method to append node and traversing the list ?
Write method to delete Node from a LinkedList.
Difference between List and LinkedList ?
Is it legal to initialize List like this ?

## Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.