Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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

Open
Miraksi wants to merge 9 commits into TheAlgorithms:master
base: master
Choose a base branch
Loading
from Miraksi:pm_rmq

Conversation

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.

Copy link
Contributor Author

Miraksi commented Mar 22, 2024

note the small change made to range_minimum_query.rs

Copy link

codecov-commenter commented Mar 22, 2024
edited
Loading

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.

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?

Copy link
Contributor Author

Miraksi commented Apr 23, 2024
edited
Loading

@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)

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
Reviewers

@imp2002 imp2002 Awaiting requested review from imp2002 imp2002 is a code owner

@vil02 vil02 Awaiting requested review from vil02

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /