+ 3

How do you find if there is any loop in singly linked list? How do you find the start of the loop

4th Nov 2017, 11:49 PM
abderrahmane Mustapha
abderrahmane Mustapha - avatar
3 Respostas
+ 8
What do you mean by loop?
4th Nov 2017, 11:51 PM
qwerty
qwerty - avatar
0
Its pretty ingenious but what you do is that you have two pointers starting at the head of the list. The first you keep advancing by two nodes, the other by one node. If they ever land on the same node you have found a loop. That algorithm blew my mind when I first heard about it :D
5th Nov 2017, 3:45 AM
Schindlabua
Schindlabua - avatar