Test if single linked list is circular by traversing it only once

Posted by user1589754 on Stack Overflow See other posts from Stack Overflow or by user1589754
Published on 2013-06-30T10:15:58Z Indexed on 2013/06/30 10:21 UTC
Read the original article Hit count: 274

I am a fresher and I was asked this question in a recent interview I gave.

The question was --- By traversing each element of linked list just once find if the single linked list is circular at any point.

To this I answered that we will store reference of each node while traversing the list in another linked list and for every node in the list being tested we will find if the reference exists in the list I am storing the references.

The interviewer said that he needs a more optimized way to solve this problem.

Can anyone please tell me what would be a more optimized method to solve this problem.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about linked-list