954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

To find whether Single Linked List is looped.

Hi all,

What is the effficient way to check whether a single linked list is looped somewhere.The number of nodes in the list is not known.
In that case traversal of SLL will go into an infinite loop.

One solution I have is to store each address of node in array and compare the nest address with the address in the array. But this solution will be of order O(n*n). Can somebody give me an efficient solution.

dilip.mathews
Junior Poster in Training
89 posts since Jun 2006
Reputation Points: 16
Solved Threads: 3
 

For a discussion of detecting cycles in linked lists, see http://ostermiller.org/find_loop_singly_linked_list.html

-bobd-

bobd
Newbie Poster
4 posts since Jun 2004
Reputation Points: 10
Solved Threads: 0
 

Thnks BOBD

dilip.mathews
Junior Poster in Training
89 posts since Jun 2006
Reputation Points: 16
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You