This repository contains Python implementations of two spatial data structures: R-Tree and K-D Tree.
We created this for our Algorithm Analysis project to understand how these algorithms work, test their performance, and visualize the results.
- Purpose: Used for indexing spatial objects (rectangles).
- Features:
- Insertion with node splitting.
- Range search (finding items in a query box).
- Visualization using Matplotlib.
- Purpose: Used for organizing points in 2D space.
- Features:
- Tree construction using median splitting.
- K-Nearest Neighbors (k-NN) search.
- Performance comparison (K-D Tree vs. Brute Force).
- Visualization of the partitioning.
You need Python 3 and the matplotlib library for visualizations.
pip install matplotlib- Navigate to the
RTreefolder. - Run the test script:
python test.py
- The script will print the query time and save an image named
rtree_visualization.png.
- Navigate to the
KDTreefolder. - Run the test script:
python test.py
- The script will show the speedup compared to brute force search and save an image named
kdtree_visualization.png.
The code generates images to show how the data is structured:
- R-Tree: Shows the bounding boxes (MBRs) and the query area.
- K-D Tree: Shows the splitting lines and the nearest neighbors found.