How can we remove loops in a linked list? What are the functions of fast and slow pointers?



How can we remove loops in a linked list? What are the functions of fast and slow pointers?..

Answer / Vishwash Kumar Singh

To detect and remove a loop in a linked list, use Floyd's cycle-finding algorithm. This method uses two pointers: a fast pointer (covering more nodes at each step) and a slow pointer (covering one node at each step). If there is a loop, the fast pointer will meet the slow pointer at some point in the loop. To remove the loop, modify the linked list such that the last node of the loop points to null.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What do you mean by linear probing?

1 Answers  


How do you sort large data?

1 Answers  


Is it possible to make an array volatile in java?

1 Answers  


Can you declare an array without assigning the size of an array?

0 Answers  


How do you represent a linked list?

1 Answers  


simple algorithm for bubble sort?

1 Answers  


What is difference between an Array and ArrayList?

1 Answers   UGC Corporation,


What do you understand by stable sort?

1 Answers  


Is array static or dynamic?

1 Answers  


input function and output function in c language

2 Answers   TCS,


Can arraylist store primitives?

1 Answers  


What is a linear search?

1 Answers  


Categories