I have a problem about graphs.
In my API , I need to check if a list which contains relations between objects IDs has a circle before it is saved in the database.
The information that is gives to me is something like this below:
[
{10, 2},
{20, 32},
{45, 90}
]
As a result , I need to check either the form of the relationship and cycle or not.
Example:
If I have
[{1, 6}, {3, 1}, {3, 4}, {4, 3}, {5, 2}, {5, 3}, {5, 4}, {6, 4}, {6, 5}]
there will be 2 circles:
- The first will be
3
→4
→3
and- the second will be
6
→4
→3
→1
→6
Notes:
The language I need to use is C#. The program must be the fastest as possible and I don't have access to the database to create any functions there. Also, I don't need to get all the possible circles.I need just one and it will be enough in order to return either TRUE
or FALSE
.
Could anyone give me some advice?