BFPRT
Median of Medians Quickselect Algorithm
About
This package implements fast median finding with the median of medians selection algorithm, also known as BFPRT (named after the authors of Blum et al. (1973)). It can be used to find the kth smallest value in a list, also known as the "kth order statistic".
When k is halfway through a list, then quickselect finds the median of the list in O(n) time. While this asymptotically linear algorithm is provably optimal, the constant factor overhead is known to be large, making this approach less useful in practice. In theory, however, the median of medians trick can be a very powerful proof step.
This package is intended primarily as a learning tool rather than a practical implementation. For faster runtime on most reasonably sized problems, prefer standard implementations of the median.
Installation
pip install bfprt
Usage
from bfprt import select_fast
# Items can have any type that implements less-than comparison
items = [4, 2, 1, 9, 5, 8]
# We want to get the kth smallest element from the list
k = 3
# This is the index of the kth smallest element
selected_index = select_fast(items, k)
# If k is len(items) // 2, then this is the median
kth_order_statistic = items[selected_index]
Installing from source
Install using Poetry
poetry install
Metadata
Release files for bfprt 0.3.0
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 |
|---|---|---|---|---|
| bfprt-0.3.0.tar.gz | 4.0 kB | Without provenance | Details for bfprt-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bfprt-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for bfprt-0.3.0-py3-none-any.whl |
Total release size: 8.1 kB
Release files / bfprt-0.3.0.tar.gz
| Download URL | bfprt-0.3.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
464088d623517b1c41c9a275081e87390c4f52fa228e7d250787cb4c8490c80c
|
|
BLAKE2b-256 checksum How to use checksums |
4bcc06fbf36353ff7f3f51fbd1712eab99b022850a39964aab1c29406c2279fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.12 Darwin/22.6.0
|
Release files / bfprt-0.3.0-py3-none-any.whl
| Download URL | bfprt-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da765a47c398d0507f21b9fd05bb280cf15bc1b7cca2f78eaa94b65030849832
|
|
BLAKE2b-256 checksum How to use checksums |
a85656b5bb7fd0504747ebca259848c20d691cbd488784e473cec88256888f0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.12 Darwin/22.6.0
|
Security for bfprt 0.3.0
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.