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

added a plus-minus-one range minimum query data structure #694

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Miraksi
Copy link
Contributor

@Miraksi Miraksi commented Mar 22, 2024

Plus-Minus-One RangeMinimumQuery in Rust

Description

A data structure that can answer range minimum queries for arrays, where two consecutive entries differ by exactly one. This implementation achieves an O(n) build time and a O(1) query time for n being the length of the input array. The relevancy of this data structure is given by the combination with Cartesian trees, which leads to an implementation of the general range minimum query in O(n) build time and O(1) query time.

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
Copy link
Contributor Author

Miraksi commented Mar 22, 2024

note the small change made to range_minimum_query.rs

@codecov-commenter
Copy link

Codecov Report

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

Project coverage is 94.65%. Comparing base (9572098) to head (136c724).
Report is 3 commits behind head on master.

Files Patch % Lines
src/data_structures/plus_minus_rmq.rs 83.44% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #694      +/-   ##
==========================================
- Coverage   94.71%   94.65%   -0.07%     
==========================================
  Files         293      294       +1     
  Lines       23351    23496     +145     
==========================================
+ Hits        22118    22239     +121     
- Misses       1233     1257      +24     

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

Copy link

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 22, 2024
@vil02 vil02 added dont-close and removed stale labels Apr 22, 2024
@vil02
Copy link
Member

vil02 commented Apr 23, 2024

@Miraksi could you please provide me with more details? +-1 range minimum queries on arrays does not say much to me.

By the way, do you see some change for some common interface for PlusMinusOneRMQ and RangeMinimumQuery?

@Miraksi
Copy link
Contributor Author

Miraksi commented Apr 23, 2024

@Miraksi could you please provide me with more details? +-1 range minimum queries on arrays does not say much to me.

For +-1 RMQ we assume that two consecutiv entries in a given list differ by exactly one. This enables us to use clever bit operations to enhance the runtime complexity of range minimum queries on this list.
The idea and also main use case of the +-1 range minimum query is to achieve a lowest common ancestor implementation quite easily (see https://cp-algorithms.com/graph/lca_farachcoltonbender.html#implementation ).

I would love to see this data structure added, as it will lead to an optimal (from a time complexity point) Lowest Common Ancestor runtime. This in turn can be extended to an optimal RMQ implementation, having a construction time of O(n) and a query time of O(1)

@Miraksi
Copy link
Contributor Author

Miraksi commented Apr 23, 2024

By the way, do you see some change for some common interface for PlusMinusOneRMQ and RangeMinimumQuery?

I'm not sure as to what you mean by common interface.

Since PlusMinusOneRMQ works on a smaller input space than RangeMinimumQuery, they probably should not need a common interface. For an implementation of the optimal RMQ, which I want to contribute, after this is merged, a common interface would be appropriate

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

Successfully merging this pull request may close these issues.

None yet

3 participants