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 9 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 Miraksi requested review from imp2002 and vil02 as code owners March 22, 2024 20:37
@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-commenter commented Mar 22, 2024

Codecov Report

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

Project coverage is 94.98%. Comparing base (5f0eab8) to head (5a4797a).

Files Patch % Lines
src/data_structures/plus_minus_rmq.rs 83.33% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #694      +/-   ##
==========================================
- Coverage   95.05%   94.98%   -0.08%     
==========================================
  Files         306      307       +1     
  Lines       22733    22877     +144     
==========================================
+ Hits        21609    21729     +120     
- Misses       1124     1148      +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.

3 participants