944,199 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2726
  • C RSS
Jul 11th, 2006
0

To find whether Single Linked List is looped.

Expand Post »
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.
Similar Threads
Reputation Points: 16
Solved Threads: 3
Junior Poster in Training
dilip.mathews is offline Offline
89 posts
since Jun 2006
Jul 11th, 2006
0

Re: To find whether Single Linked List is looped.

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

-bobd-
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bobd is offline Offline
4 posts
since Jun 2004
Jul 11th, 2006
0

Re: To find whether Single Linked List is looped.

Thnks BOBD
Reputation Points: 16
Solved Threads: 3
Junior Poster in Training
dilip.mathews is offline Offline
89 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: basics of OOP
Next Thread in C Forum Timeline: DirectSound WAVEFORMATEX Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC