https://github.com/alesanfra/kdtree
Multidimensional binary search tree for associative searching
https://github.com/alesanfra/kdtree
binary-search-tree multidimensional-trees tree
Last synced: 6 months ago
JSON representation
Multidimensional binary search tree for associative searching
- Host: GitHub
- URL: https://github.com/alesanfra/kdtree
- Owner: alesanfra
- License: gpl-3.0
- Created: 2020-11-05T20:15:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-13T22:10:58.000Z (over 5 years ago)
- Last Synced: 2025-08-20T21:01:03.912Z (11 months ago)
- Topics: binary-search-tree, multidimensional-trees, tree
- Language: Python
- Homepage:
- Size: 42 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://sonarcloud.io/dashboard?id=alesanfra_kdtree)
[](https://codecov.io/gh/alesanfra/kdtree)
# KDTree
Implementation of a multidimensional binary search tree for associative searching
## References
Jon Louis Bentley. Multidimensional binary search tree used for associative searching. September 1975.
## Usage
```python
from kdtree import BinSearchTree, Bound, Node, Region
# Create a new tree
tree = BinSearchTree(dimension=2)
# Insert some nodes into the tree
tree.insert(Node((50, 50)))
tree.insert(Node((10, 70)))
tree.insert(Node((80, 85)))
tree.insert(Node((25, 20)))
tree.insert(Node((40, 85)))
tree.insert(Node((70, 85)))
tree.insert(Node((10, 60)))
# Create rectangle from a bound array as described in the article
# Element 2*j is lower bound and element (2*j)+1 is upper bound of dimension j
rectangle_1 = Region.from_bounds_array(69, 71, 84, 86)
# Create rectangles as a list of Bound object
rectangle_2 = Region(Bound(69, 71), Bound(84, 86))
# Search
nodes = tree.regional_search(rectangle_1)
print("Nodes within region:", nodes)
```