Package org.jgrapht.alg.cycle
Implementation Note: All the implementations work correctly with loops but not with multiple duplicate edges.
Performance Notes: The worst case time complexity of the algorithms for finding cycles in directed graphs is:
- Tiernan - O(V.const^V)
- Tarjan - O(VEC)
- Johnson - O(((V+E)C)
- Szwarcfiter and Lauer - O(V+EC)
The worst case performance is achieved for graphs with special structure, so on practical workloads an algorithm with higher worst case complexity may outperform an algorithm with lower worst case complexity. Note also that "administrative costs" of algorithms with better worst case performance are higher. Also higher is their memory cost (which is in all cases O(V+E)).
The package author's workloads contain typically several hundred nodes and from tens to several thousand simple cycles. On these workloads the algorithms score by performance (best to worst ) so :
- Szwarcfiter and Lauer
- Tarjan
- Johnson
- Tiernan
Literature:
- J.C.Tiernan An Efficient Search Algorithm Find the Elementary Circuits of a Graph., Communications of the ACM, V13, 12, (1970), pp. 722 - 726.
- R.Tarjan, Depth-first search and linear graph algorithms., SIAM J. Comput. 1 (1972), pp. 146-160.
- R. Tarjan, Enumeration of the elementary circuits of a directed graph, SIAM J. Comput., 2 (1973), pp. 211-216.
- D.B.Johnson, Finding all the elementary circuits of a directed graph, SIAM J. Comput., 4 (1975), pp. 77-84.
- J.L.Szwarcfiter and P.E.Lauer, Finding the elementary cycles of a directed graph in O(n + m) per cycle, Technical Report Series, #60, May 1974, Univ. of Newcastle upon Tyne, Newcastle upon Tyne, England.
- P.Mateti and N.Deo, On algorithms for enumerating all circuits of a graph., SIAM J. Comput., 5 (1978), pp. 90-99.
- L.G.Bezem and J.van Leeuwen, Enumeration in graphs., Technical report RUU-CS-87-7, University of Utrecht, The Netherlands, 1987.
- K. Paton, An algorithm for finding a fundamental set of cycles for an undirected linear graph, Comm. ACM 12 (1969), pp. 514-518.
-
Interface Summary Interface Description DirectedSimpleCycles<V,E> A common interface for classes implementing algorithms for enumeration of the simple cycles of a directed graph.UndirectedCycleBase<V,E> A common interface for classes implementing algorithms for finding a cycle base of an undirected graph. -
Class Summary Class Description HawickJamesSimpleCycles<V,E> Find all simple cycles of a directed graph using the algorithm described by Hawick and James.HierholzerEulerianCycle<V,E> An implementation of Hierholzer's algorithm for finding an Eulerian cycle in Eulerian graphs.JohnsonSimpleCycles<V,E> Find all simple cycles of a directed graph using the Johnson's algorithm.PatonCycleBase<V,E> Find a cycle base of an undirected graph using the Paton's algorithm.SzwarcfiterLauerSimpleCycles<V,E> Find all simple cycles of a directed graph using the Schwarcfiter and Lauer's algorithm.TarjanSimpleCycles<V,E> Find all simple cycles of a directed graph using the Tarjan's algorithm.TiernanSimpleCycles<V,E> Find all simple cycles of a directed graph using the Tiernan's algorithm. -
Enum Summary Enum Description HawickJamesSimpleCycles.Operation