Group nearby shapes inside boxes, and boxes inside bigger boxes, to search maps fast.
An R-tree is a tree for storing shapes and areas on a map. It puts nearby shapes inside a box, puts nearby boxes inside a bigger box, and so on up to one box that covers everything.
Points are easy: a point is in a square or it is not. Real map data has shapes: a lake, a road, a building, a delivery zone. A shape can cross many squares of a grid, and then you have to store it many times. The R-tree avoids this by giving every shape one place in the tree.
Every shape is first wrapped in its bounding box, the smallest rectangle that contains it. Boxes that are near each other are grouped, and the group gets its own bigger bounding box. Groups of groups get a still bigger box, until one root box covers all. The tree is balanced: all leaves are at the same depth, like a B-tree.
A search says: “I want everything touching this window.” Start at the root. For every child box that touches the window, go inside. For every child box that does not, skip it and everything beneath it. At a leaf, check the real shapes.
| Variant | Idea | Good and bad |
|---|---|---|
| Classic R-tree | Insert into the box that grows least; split a full node into two | Simple, but overlap can grow |
| R*-tree | Smarter choice and split rules, plus re-inserting entries to reduce overlap | Faster queries, slower inserts |
| R+-tree | Boxes at one level never overlap, but a shape may be stored in several leaves | Searches follow one path, at the cost of duplicates |
| Packed / bulk-loaded | Sort the data by place and build the tree from the bottom | Best for data that rarely changes (the visualizer builds this way) |
Solid outlines = bottom boxes (cyan). Dashed outlines = boxes of boxes. Bright = visited by the search, faint = skipped. Green shapes = found.
A simplified, bulk-built R-tree: shapes are packed into boxes, and boxes into bigger boxes, level by level. Real R-trees also support inserts and splits, but the search works the same way: skip every box that does not touch the window. Shapes are made with a seeded generator, so the data never changes between visits.
| Term | Meaning in easy words |
|---|---|
| Bounding box / MBR | The smallest rectangle (minimum bounding rectangle) that holds a shape or a group of boxes |
| Leaf | A node that holds the boxes of real shapes |
| Inner node | A node that holds the boxes of its child nodes |
| Overlap | Area covered by two sibling boxes at once; it forces a search to follow both |
| Fan-out | How many entries one node holds (the 'entries per box' in the visualizer) |
| Balanced | All leaves are at the same depth |
| Split | Dividing a full node into two |
| Bulk loading | Building a tree from sorted data in one pass, bottom up |
| Window query | Find everything touching a rectangle |
| Nearest neighbour | Find the shape closest to a point |
| Filter and refine | Cheap box test first, exact shape test second |
| Choice | We gain | We lose |
|---|---|---|
| Bigger nodes (high fan-out) | A shorter tree and fewer disk reads | More boxes to compare inside each node |
| Smaller nodes | Tighter, more precise boxes | A taller tree |
| Bulk-loaded tree | Little overlap, fast queries | Not made for many later changes |
| Built by inserts | Always up to date | More overlap over time |
| R*-tree rules | Better queries | Slower inserts |
| R-tree | Good for shapes and disks | More complex than a quad tree or grid for plain points |