-
Notifications
You must be signed in to change notification settings - Fork 271
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 Sparse table data structure for RMQ #414
Conversation
Codecov Report
@@ Coverage Diff @@
## master #414 +/- ##
=============================================
- Coverage 98.611% 98.573% -0.039%
=============================================
Files 27 29 +2
Lines 3530 3645 +115
=============================================
+ Hits 3481 3593 +112
- Misses 49 52 +3
|
self.table[i][j-1], | ||
self.table[i+(1 << (j-1))][j-1]) | ||
|
||
def __rangequery__(self, L, R, comp=_comp): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __rangequery__(self, L, R, comp=_comp): | |
def query(self, left, right, comp=_comp): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a scope of flexibility here. One may find gcd as well by replacing comp with gcd. See, https://gist.github.com/yDeepak1889/dee5cce7fff3354c50ff07a43a5be981
I am not sure about this. We will discuss more in the meeting.
The PR syntactically is correct. There are some memory issues with implementation. We can fix that though. |
Thanks @pratikgl |
[WIP] I have added sparse table for solving Range Minimum Query
References to other Issues or PRs or Relevant literature
I am trying to replicate this idea which I had implemented a while ago in C++.
https://github.com/pratikgl/Data-Structures-and-Algorithms/blob/master/RMQ/sparse_table.cpp
The sparse table implementation for RMQ will take
O(n*log(n)))
time for preprocessing andO(1)
time for each queryMore details could be find here:
Brief description of what is fixed or changed
Other comments