To find whether Single Linked List is looped.

Reply

Join Date: Jun 2006
Posts: 89
Reputation: dilip.mathews is an unknown quantity at this point 
Solved Threads: 3
dilip.mathews's Avatar
dilip.mathews dilip.mathews is offline Offline
Junior Poster in Training

To find whether Single Linked List is looped.

 
0
  #1
Jul 11th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 3
Reputation: bobd is an unknown quantity at this point 
Solved Threads: 0
bobd bobd is offline Offline
Newbie Poster

Re: To find whether Single Linked List is looped.

 
0
  #2
Jul 11th, 2006
For a discussion of detecting cycles in linked lists, see http://ostermiller.org/find_loop_sin...nked_list.html

-bobd-
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 89
Reputation: dilip.mathews is an unknown quantity at this point 
Solved Threads: 3
dilip.mathews's Avatar
dilip.mathews dilip.mathews is offline Offline
Junior Poster in Training

Re: To find whether Single Linked List is looped.

 
0
  #3
Jul 11th, 2006
Thnks BOBD
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC