I have a data structure that is in the form of a list of nodes
[ID: 1, Name: "Node 1"],
[ID: 2, Name: "Node 2"],
[ID: 3, Name: "Node 3"],
[ID: 4, Name: "Node 4"]
and edges, of the form
[StartNode: 1, EndNode: 2],
[StartNode: 2, EndNode: 3]
and so on.
This data is stored in SQL and processed with C# and Angular. Nodes can be multiply connected, but the one thing that breaks the interface is a circular reference. I cannot have Node 1 -> Node 2 -> Node 3 -> Node 1.
Somehow a circular reference has crept into our database, but I can't figure out where it is. It's probably a 'small' circle, of three nodes that are connected together when they shouldn't, but I can't be sure.
How can I write some sort of recursive algorithm to find out where the circular reference is? Can I do this through a series of joins in SQL?