Skip to content

added a decremental connectivity data structure #684

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

Merged
merged 16 commits into from
Apr 23, 2024

Conversation

Miraksi
Copy link
Contributor

@Miraksi Miraksi commented Mar 14, 2024

Decremental Connectivity Query in Rust

Description

A data structure that, given a forest, allows dynamic-connectivity queries. Meaning deletion of an edge (u,v) and checking whether two vertecies are still connected. This implementation of an algorithm developed by Shimon Even and Yossi Shiloach, has a precomputiation phase with complexity O(n) (n being the number of verticies), a deletion complexity of O(log n) and a connectivity-query complexity of O(1).

New feature

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@Miraksi Miraksi requested review from imp2002 and vil02 as code owners March 14, 2024 23:15
@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 97.89474% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 94.76%. Comparing base (10c986d) to head (1a656ee).
Report is 15 commits behind head on master.

Files Patch % Lines
src/graph/decremental_connectivity.rs 97.89% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   94.70%   94.76%   +0.06%     
==========================================
  Files         292      297       +5     
  Lines       23292    22148    -1144     
==========================================
- Hits        22058    20989    -1069     
+ Misses       1234     1159      -75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Miraksi Miraksi requested a review from vil02 March 31, 2024 08:52
@vil02
Copy link
Member

vil02 commented Apr 3, 2024

@Miraksi could you please share some reliable source about this data structure?

@Miraksi
Copy link
Contributor Author

Miraksi commented Apr 3, 2024

@Miraksi could you please share some reliable source about this data structure?

grafik
Shimon Even and Yossi Shiloach,
An On-Line Edge Deletion Problem,
SIAM Journal on Computing, 1972

This also is the paper took as reference, which was also referenced in the wikipedia entry on decremental connectivity
(I dont know if im allowed to share the whole paper for copyright reasons, which is why I only posted the relevant section)

@vil02
Copy link
Member

vil02 commented Apr 4, 2024

@Miraksi your implementation works only for forests (connected list of trees), but the it is possible to (mis)use it for any graph. Do you see some reasonable way to avoid that?

By the way: feel free to rebase.

@Miraksi
Copy link
Contributor Author

Miraksi commented Apr 5, 2024

@Miraksi your implementation works only for forests (connected list of trees), but the it is possible to (mis)use it for any graph. Do you see some reasonable way to avoid that?

By the way: feel free to rebase.

Good Idea! I've added a function that checks whether the given graph is acyclic (ignoring cycles of lenght one). This check runs in O(n) time, so its basically for free.
Should the constructor panic, or return a result type?

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

Looks good enough, thanks!

@vil02 vil02 force-pushed the decremental_connectivity branch from 8f9be6b to ad7e1a6 Compare April 23, 2024 18:50
@vil02 vil02 merged commit b20faef into TheAlgorithms:master Apr 23, 2024
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.

3 participants