This data structure solves the range minimum query problem of finding the minimal value in a sub-array of an array of comparable objects. Different from the original problem, this data structure also supports updating the values.
Installation
This package is available on PyPI. Just use pip install -U RangeMinQuery to install it. Then you can import it using from RangeMinQuery import SegmentTree.
Usage
Initialization
Use SegmentTree() to initialize the tree with a set of keys, in comparable and hashable type.
-
func=minspecifies how the best value is computed for any range of keys. -
default=Nonespecifies the default value for each key. -
maxChildNum=2specifies the maximum number of children for each node.
tree = SegmentTree(
{1, 2, 3, 4, 5},
func=min, default=0, maxChildNum=2
)
The space complexity should be $O(n)$.
Updating
You need to use update() to initialize the values, or update the values if necessary, by specifying a dictionary of key/value pairs. Currently, adding new keys is not supported yet.
tree.update({1: 3, 4: 6})
Given m values updated, the time complexity should be $O(m^2)$.
Querying
Use query() to to find the best value of a range of keys. The range is denoted by a tuple (a, b), representing each key x such that a <= x < b. The range here is closed on the left side and open on the right side, consistent with Python tradition.
tree.query((1, 3))
The time complexity should be $O(log n)$.
Metadata
Release files for RangeMinQuery 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| RangeMinQuery-0.2.tar.gz | 3.0 kB | Without provenance | Details for RangeMinQuery-0.2.tar.gz |
Release files / RangeMinQuery-0.2.tar.gz
| Download URL | RangeMinQuery-0.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bb003ebd601860398f235049a085057f9cbe6f166c70e9f4a879042c96d80a6
|
|
BLAKE2b-256 checksum How to use checksums |
ca35678a6bd7ac444db73d4da5ae16692f38a5f6c0a7b8a4a8242c32df441b3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for RangeMinQuery 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.