Quad Tree
Quad Tree
At its core, a quad tree is a way of dividing space The structure is recursive, meaning each node
into smaller and smaller sections, creating a can be divided into four quadrants which may
tree-like structure with each section themselves be divided into four, and so on.
represented by a node.
One major advantage of quad trees is that they Quad trees can be extended for use in data with
can efficiently store sparse data, allowing for more than two dimensions, such as 3D space or
quick retrieval of individual points or small time-series data.
regions of a map.
The Building Blocks of a Quad Tree
1 Root Nodes
The root node in a Quad Tree divides
the entire 2D space into four
quadrants. Subsequent internal nodes
refine this division recursively, forming
a hierarchical structure. This flexible
Internal Nodes
These nodes divide the 2D space into four
2 and scalable organization optimizes
sections known as quadrants. Each quadrant tasks like spatial indexing, collision
corresponds to a child node of the internal detection etc.
node. This recursive subdivision continues,
creating a hierarchical structure. Internal Leaf nodes
nodes store information about the spatial
3 Leaf nodes in a Quad Tree are the bottom-
boundaries. level entities that store actual data points or
values within the spatial subdivisions. They
represent the finest granularity of the tree,
containing information about specific regions of
the 2D space.
Construction of Quad Trees
The process of creating a quad- The points are split based on a At some point, nodes with few or
tree involves recursively dividing split criteria which can be depth, no points may be removed from
the 2D space into smaller parts number of points, or a minimum the tree to save computing
until each part contains a single size for each quadrant. resources.
point or region.
Operations on Quad Trees
1 Searching
Searching in a quad-tree is essentially walking down the tree, starting at the root node
and testing whether a given point intersects with each quadrant
2 Inserting
To insert a new point, the tree is recursively searched and the appropriate empty leaf
node is found.
3 Deleting
Deleting a leaf node works similarly to inserting a new node. The empty node is
deleted, and its parent is checked to see if it is now empty as well.
Advantages and Disadvantages of Quad Trees
Quad Trees facilitate fast data retrieval of Quad Trees are adaptive in terms of node
individual points and small regions of a map. creation, making them cost-effective and
saving space
Quad Trees can be used in n-dimensional There is always an overhead cost that comes
data structures, making them versatile for a with traversing a tree, making it less efficient
wide range of applications. than other data organization techniques.
Examples and Use Cases