Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement connected_subgraphs() #35

Merged
merged 1 commit into from
Mar 1, 2025

Conversation

merkys
Copy link
Contributor

@merkys merkys commented Feb 13, 2025

This PR introduces connected_subgraphs() which generates all the connected subgraphs of a given graph. I needed this for my applications, and I was unable to find anything similar even in Python's NetworkX.

Apparently, there does not seem to be a trivial algorithm for that. Intuitive solution of checking each of 2^N vertex subsets for connectivity is quite expensive and inefficient for sparse graphs.

My implementation is based on a modified BFS starting at each vertex and forking off on every neighbour. Intuitively (= no proof) this should work on directed and multiedge graphs, as neighbours() is used in this modified BFS.

Current implementation could be made more efficient by using something else than the difference of Set::Object objects to find the next expansion tier for the modified BFS. Maybe a matrix form. But for small graphs this does the trick.

@mohawk2 mohawk2 merged commit 9026639 into graphviz-perl:master Mar 1, 2025
6 checks passed
@mohawk2
Copy link
Collaborator

mohawk2 commented Mar 1, 2025

Thank you! Released as 0.9734.

@merkys merkys deleted the connected-subgraphs branch March 3, 2025 10:25
@merkys
Copy link
Contributor Author

merkys commented Mar 3, 2025

Thanks a lot for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants