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

Find interval min, max efficiently #110

Open
cmpute opened this issue Oct 5, 2021 · 2 comments
Open

Find interval min, max efficiently #110

cmpute opened this issue Oct 5, 2021 · 2 comments

Comments

@cmpute
Copy link

cmpute commented Oct 5, 2021

Is there any efficient way to query the min/max value at given position in the intervaltree? The only method I'm aware of to find the min/max value is like max(tree[point]). Ideally a better way is to trace the min/max value in each node while updating the tree, which is O(log n) instead of O(n). Is this feasible in the library?

@chaimleib
Copy link
Owner

O(log n) is better than O(n).

If you are aiming for O(1) time for each insertion and O(1) for the final query, that is possible, but best solved with a different data structure than this interval tree.

@cmpute
Copy link
Author

cmpute commented Oct 28, 2021

Thanks for the reply. I meant that, the current possible best time is O(log n) for insertion but O(n) for min/max query (you have to iterate over the query results). If we add tracking of min/max value for subtree in each node, then the min/max query could be O(1) while the overhead for insertion is very small.

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

No branches or pull requests

2 participants