Algorithm for finding all cycles in a directed graph on C++ using Adjacency matrix

為{幸葍}努か 提交于 2019-12-05 20:53:15

This problem has exponential complexity in the general case. The thing is that if each vertex is connected to each then the count of all graph cycles is more than 2^n (any subset of nodes forms several cycles).

Thus there is no good algorithm in the general case. To find some cycle you may use breadth-first search. To find all cycles you should use brute force algorithm.

If C++ is the problem then change for another language. up to my knowledge C++ does not have particular feature that make it more efficient/convenient to work on graph matters. Alternatively you might want to look for a framework that will abstract the low level, letting you focusing on the high-level question. You might consider Boost Graph library for that purpose.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!