# What is quadtree data structure?

## What is quadtree data structure?

A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are the two-dimensional analog of octrees and are most often used to partition a two-dimensional space by recursively subdividing it into four quadrants or regions.

## How do you use a quadtree for collision detection?

1. Insert an object into the quadtree: Check if the object intersects the current node.
2. Delete an object from the quadtree:
3. Test if an object intersects any object inside the quadtree:
4. Test for all collisions between all objects inside the quadtree:

How do you insert data into a quadtree?

Inserting data into a quadtree involves recursively determining which of the four children (quadrants) the data-point should occupy, until you reach a leaf-node (quadrant).

### What kind of data structure does a quadtree have?

Trees generally have internal nodes (nodes that have at least one child) and leaf nodes which have no children. These nodes holds data that are ordered in a hierarchical order. A quadtree is a tree data structure in which each node has zero or four children.

### Which is a use case for a quadtree?

A quadtree is a tree data structure in which each node has zero or four children. Its main peculiarity is its way of recursively dividing a flat 2-D space into four quadrants. Some quadtree use-cases includes Image processing, sparse data storage, spatial indexing etc. This article focuses on the spatial-indexing use-case.

How are quad trees used to store data?

Quadtrees are trees used to efficiently store data of points on a two-dimensional space. In this tree, each node has at most four children. Divide the current two dimensional space into four boxes. If a box contains one or more points in it, create a child object, storing in it the two dimensional space of the box Recurse for each of the children.

19/03/2020