Skip to content

Conversation

@daehiff
Copy link
Contributor

@daehiff daehiff commented Nov 24, 2024

Motivation

This pull request adds a function to compute articulation points in a graph using Tarjan's algorithm, implemented with an iterative approach. Articulation points are nodes whose removal increases the number of connected components in the graph.
Currently, petgraph lacks an implementation for this functionality. This makes it impossible to for instance determine if a vertex of a graph is cutting with petgraph.

Note: This approach is not a direct replication of existing implementations (e.g., [here](https://www.geeksforgeeks.org/tarjan-algorithm-find-strongly-connected-components/)), as it avoids recursion entirely.

Runtime

Tarjan's algorithm is an efficient solution to this problem, with a time complexity of (O(V + E)), making it well-suited for large graphs.

@daehiff daehiff changed the title Art points Add articulation points implementation Nov 24, 2024
@starovoid
Copy link
Collaborator

Hi, great job!

But I think it will be better the implementation using stack instead of recursion. Just like it was with the bridge edges search algorithm in PR #590.

Practice has shown that a recursive implementation can face the problem of stack overflow.

@daehiff
Copy link
Contributor Author

daehiff commented Nov 25, 2024

Hey, thanks for the quick reply!

That is a good suggestion! I'll update the PR.
Do you have any other requirements (testing concepts ect.), we should be aware of?

@starovoid
Copy link
Collaborator

Yes, I have two thoughts

Picky testing

I think it would be a good idea to write some randomized tests.

In general, the algorithm may look like this:

  1. Creating a random graph on a random number of vertices;
  2. Find the articulation points;
  3. We remove the found vertices from the graph one by one and check that each time the number of connectivity components increases;

Later, when version 0.7.0 is released, I plan to open a PR with the addition of a randomized test for bridges implementation too.

Add bench

petgraph has a good tradition of adding performance tests for new algorithms.
I think it would be logical to add a benchmark identical to #590, since the algorithms are similar.

@daehiff daehiff force-pushed the art-points branch 2 times, most recently from 47cc1cd to 3fbc423 Compare December 2, 2024 23:44
@daehiff
Copy link
Contributor Author

daehiff commented Dec 2, 2024

Alright, sorry the late reply.

I have added:

  1. A benchmark similar to bridges
  2. A few more tests and some other graph structures
  3. A quickcheck test for random graphs

Anything further or do you have other comments on the implementation?

@starovoid
Copy link
Collaborator

I think all is top class now.
It remains to wait for the maintainers' review.

@XVilka
Copy link
Member

XVilka commented Dec 23, 2024

@daehiff please update the PR description to describe the reasons for this implementation, etc.

@daehiff
Copy link
Contributor Author

daehiff commented Dec 23, 2024

@XVilka all checks have been passed and there has been some review comments.

Is there a timeline or a ways how we can get in touch? It is kind of hard todo a contribution without knowing contribution guidelines ect.

I asked @ABorgna via discord, but no response on that end.

@XVilka
Copy link
Member

XVilka commented Dec 23, 2024

@XVilka all checks have been passed and there has been some review comments.

Is there a timeline or a ways how we can get in touch? It is kind of hard todo a contribution without knowing contribution guidelines ect.

I asked @ABorgna via discord, but no response on that end.

I forgot we have a DIscord. Just joined it.

Copy link
Member

@ABorgna ABorgna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I mostly only have nitpicks.

fn _dfs<G>(
g: &G,
target_node: usize,
visited: &mut Vec<bool>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vec<bool> uses one byte per element, since it needs to support arbitrary references.

Use a FixedBitSet instead.

_dfs(
&g,
node_id,
&mut visited,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: This could be an auxiliary state struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a struct ArticulationPointTracker, I am kindof unhappy with the naming tho.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd normally call it "Context", but it's private so it doesn't really matter.

y-richie-y and others added 5 commits February 1, 2025 14:09
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
daehiff and others added 5 commits February 1, 2025 14:14
Co-authored-by: Agustín Borgna <agustinborgna@gmail.com>
Co-authored-by: Agustín Borgna <agustinborgna@gmail.com>
Co-authored-by: Agustín Borgna <agustinborgna@gmail.com>
Co-authored-by: Agustín Borgna <agustinborgna@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
@ABorgna ABorgna merged commit ee68efc into petgraph:master Feb 1, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-new-algorithm Category: A feature request for a new graph algorithm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants