I need to find circular dependency between classes and I immediately remember two things from the "Algorithms and Data Structures" course:
1)Finding a Loop in a Singly Linked List (Floyd’s Cycle-Finding Algorithm)
2)Depth-first search
So, I have a method that check circular dependency
private void FindDependency(IDictionary<string, IEnumerable<string>> serviceDependence)
In input, we have a dictionary that contains, for example, <"A", < "B", "C" >>
and <"B", < "A", "D" >>
, this means that class A
depends on class B
and C
. In the output, we have a circular dependency between A->B
(in the more complex situation it will be a chain of dependency).
Which algorithms should I use and why?