This is what I am trying to solve. I have a series of numbers like
1 -> 2
2 -> 3
3 -> 4
4 -> 2
2 -> 1
I need to write a program to prove if these numbers are points on a graph they form some kind of loop. In the above example 1 -> 2 -> 3 -> 4 -> 2 form a loop.
In the following example there is no loop.
1 -> 2
2 -> 3
3 -> 4
3 -> 5
Don't understand how this is a duplicate. Sorry if my question is not clear. I am trying my level best to describe it. I have set of points/numbers/nodes. They are in pair and also they have direction. For example pair of numbers are 1 -> 2 2 -> 3 1 -> 2 3 -> 4 4 -> 2 2 -> 1 3 -> 4
When these individual nodes are connected from top to bottom I will get linked lists as below 1 -> 2 -> 3 -> 1 -> 2 -> 3 -> 4 -> 2 -> 1 -> 3 -> 4
I am not looking for a repeated pattern in this set of numbers. trying to find closed loops like 1 -> 2 -> 3 -> 1 is a loop. 2 -> 3 -> 1 -> 2 is a loop. 3 -> 1 -> 2 -> 3, 2 -> 3 -> 4 -> 2, 3 -> 4 -> 2 -> 1 -> 3 etc. in this wiki link there is one loop that is 1 _. 6 -> 3 -> 1 http://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Functional_graph.svg/240px-Functional_graph.svg.png
Hope this makes the question clear!