JuliaGraphs / Graphs.jl

An optimized graphs package for the Julia programming language
http://juliagraphs.org/Graphs.jl/
Other
451 stars 87 forks source link

Implement `is_articulation` to check if vertex is articulation point #387

Open thchr opened 1 month ago

thchr commented 1 month ago

This factors out the DFS step from articulation into a separate function articulation_dfs! and then uses this new function to implement is_articulation(g, v) which checks whether v is an articulation point of g without necessarily computing all the articulation points.

The branching on isnothing(is_articulation_pts) in articulation_dfs! is a bit inelegant - as is the fact that articulation_dfs! doesn't mutate if is_articulation_pts === nothing, but it seemed the simplest way to avoid code duplication.

Aside from these additions, I revised the doc string of articulation(g) a bit (e.g., it 1. previously misleadingly stated that g had to be connected; it does not; and 2. it changed nomenclature from "articulation point" to "cut vertex" mid-sentence).

thchr commented 1 month ago

Timing-wise, is_articulation(g, v) appears to give a speed-up of about a factor of ~2 in cases I looked at, compared to v ∈ articulation(g):

julia> g = path_graph(5)
julia> articulation(g) # [2, 3, 4]
julia> @btime 2 ∈ articulation($g)   # 209.656 ns (8 allocations: 704 bytes)
julia> @btime is_articulation($g, 2) # 122.850 ns (4 allocations: 464 bytes)

julia> g = path_graph(15)
julia> articulation(g) # [2:14...]
julia> @btime 9 ∈ articulation($g)   # 453.853 ns (10 allocations: 2.16 KiB)
julia> @btime is_articulation($g, 9) # 245.286 ns (4 allocations: 624 bytes)
codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.30%. Comparing base (56e5604) to head (870597c). Report is 1 commits behind head on master.

Files Patch % Lines
src/biconnectivity/articulation.jl 98.21% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #387 +/- ## ========================================== - Coverage 97.31% 97.30% -0.01% ========================================== Files 120 120 Lines 6954 6966 +12 ========================================== + Hits 6767 6778 +11 - Misses 187 188 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.