Master 30 Software Developer interview questions covering algorithms, system design, and coding challenges.
Question 4 of 30
How to Answer 1
How to Answer 2
Example Answer
Community Answers

Tom Dushaj is a business and technology executive and the author of 'Resumes That Work.' Tom has vast experience providing solutions to Fortune 500 companies in the areas of Information Technology Consulting, ERP Software, Personnel Management, and Intern
I use Floyd's Cycle-Finding Algorithm to find the starting node of a cycle. I believe it to be the fastest method I have used. I make sure that every node is checked to see if the next one in the sequence is pointing to a temporary node or not. Here's an example of what I mean.
I can use traverse linked list pointers
Traverse linked lists using two pointers
I can move one pointer (slow_p) to one and another pointer (fast_p) by two.
If these pointers meet at the same mode, then there is a complete loop. On the other hand, if pointers do not meet, the linked list doesn't have a complete loop.

Tom Dushaj is a business and technology executive and the author of 'Resumes That Work.' Tom has vast experience providing solutions to Fortune 500 companies in the areas of Information Technology Consulting, ERP Software, Personnel Management, and Intern
Let's say for argument's sake that two cyclists (no pun intended) are pointed at the beginning of the starting line with their cycles. For clarification purposes, the two cyclists are the pointers. In this example, if we move cyclist 1 a step at a time and the second cyclist 2 steps at a time, they would eventually meet at a single point. An interviewer wants to know whether you can explain how you arrive at an answer and the reasoning behind your findings. This is important because when you explain if a link contains a cycle, you need to back that up with a verbal or written (whiteboard) example. A common response might be to mention that a meeting point is 'P' steps away from the beginning of the cycle, and the 'cyclists' meet when cyclist 1 has taken a '7' total steps toward the point.

Tom Dushaj is a business and technology executive and the author of 'Resumes That Work.' Tom has vast experience providing solutions to Fortune 500 companies in the areas of Information Technology Consulting, ERP Software, Personnel Management, and Intern
"The way I find a starting node of a cycle is to measure the length of 'R' and how far the distance is away from the cycle. That's a simple explanation. A more complex explanation I can illustrate is when cyclist 1 travels double the speed of cyclist 2, they both arrive at the same meeting point when time is constant. Since there are several examples I can give to make my point, I would like to share one more. The next pointer of each node that is traversed is made to point to this temporary node. This way, we are using the next pointer of a node as a flag to indicate whether the node has been traversed or not. If I come across a node that points to null, then the loop doesn't exist. If I find that the code runs in O(n) time complexity and uses constant memory space, then that tells me that this needs to be researched further."

Interview Coach
Jaymie
A real coach, not AI. I read every answer myself and write back with personalized feedback.
Typically responds within 24 hours.
0 - Character Count
Unlock expert responses to technical and behavioral questions interviewers ask developers.
Get StartedJump to Question

Written by Tom Dushaj
30 Questions & Answers • Software Developer

By Tom

By Tom