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 Sparse table data structure for RMQ #414

Merged
merged 24 commits into from
Oct 24, 2021
Merged

Added Sparse table data structure for RMQ #414

merged 24 commits into from
Oct 24, 2021

Conversation

pratikgl
Copy link
Member

[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 and O(1) time for each query

More details could be find here:

  1. https://cp-algorithms.com/data_structures/sparse-table.html

Brief description of what is fixed or changed

Other comments

@codecov
Copy link

codecov bot commented Oct 17, 2021

Codecov Report

Merging #414 (2c4510d) into master (c726bf2) will decrease coverage by 0.038%.
The diff coverage is 97.391%.

@@              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     
Impacted Files Coverage Δ
pydatastructs/utils/__init__.py 100.000% <ø> (ø)
...tructs/miscellaneous_data_structures/algorithms.py 95.833% <95.833%> (ø)
...ucts/miscellaneous_data_structures/sparse_table.py 97.142% <97.142%> (ø)
...astructs/miscellaneous_data_structures/__init__.py 100.000% <100.000%> (ø)
pydatastructs/utils/misc_util.py 99.043% <100.000%> (+0.148%) ⬆️

Impacted file tree graph

self.table[i][j-1],
self.table[i+(1 << (j-1))][j-1])

def __rangequery__(self, L, R, comp=_comp):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __rangequery__(self, L, R, comp=_comp):
def query(self, left, right, comp=_comp):

Copy link
Member

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.

@czgdp1807
Copy link
Member

The PR syntactically is correct. There are some memory issues with implementation. We can fix that though. RangeMinimumQuery is good. Just add a class for array data structure as well.

@czgdp1807 czgdp1807 merged commit 2a7d6c7 into codezonediitj:master Oct 24, 2021
@czgdp1807
Copy link
Member

Thanks @pratikgl

@czgdp1807 czgdp1807 mentioned this pull request Oct 24, 2021
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.

2 participants