Detecting a loop in a linked list
Problem : Given a singly linked list, find if there exist a loop.
Example
A -> B -> C -> D -> E -> C [ E again point to C]
Solutions
Method 1 - Using hashing
Traverse the list one by one and keep putting the node addresses in a Hash Table. At any point, if NULL is reached then return false and if next of current node points to any of the previously stored nodes in Hash then return true.
[Read More]