An invariant is an internal property that remains true throughout a data structure’s lifetime or across permitted transformations. It is the implementation-side counterpart to an API guarantee: algorithms update the stored data while preserving the conditions required by external clients. section 2.4
For a sorted list, the invariant is that each element is no greater than its successor. A priority queue may promise that top() returns the highest-priority element; its concrete implementation must preserve internal conditions that make this guarantee reliable. section 2.4
Use invariants as implementation checkpoints:
- State the property precisely before writing update operations. section 2.4
- Update the data model without violating the property; splitting, merging, or rearranging may be necessary. section 2.4 section 10.2.2
- Check the invariant after each structural change, because violating it can break the external API or make searches inefficient. section 2.4 section 10.2.2
R-tree maintenance
An R-tree requires every non-root leaf to contain between m and M points, every non-root internal node to contain between m and M children, and all leaves to share a level. Each node also stores the smallest axis-aligned rectangle containing its contents. Insertion splits an overflowing node; removal merges an underfull node with a sibling. These repairs restore the occupancy and bounding-rectangle invariants, while the shared leaf level keeps the tree balanced. section 10.2.2
Table 2.1 API and contract for priority queue (view table figure)
Use the priority-queue API table to compare external guarantees with the internal invariants that implementations must preserve. section 2.4
Figure 10.3 Cartesian plane representation of a (possible) R-tree for our city maps as presented in the example of figure 9.4 (the names of the cities are omitted to avoid confusion). This R-tree contains 12 bounding rectangles, from R1 to R12, organized in a hierarchical structure. Notice that rectangles can and do overlap, as shown in the bottom half.
Use the R-tree diagram to connect bounding-rectangle invariants with hierarchical spatial organization and overlapping regions. section 10.2.2











