Quadtrees are trees implemented to efficiently store data of points on a two-dimensional space. In this tree, each node has maximum four children.
We can build a quadtree from a two-dimensional area implementing the following steps
Quadtrees are implemented in image compression, where each node consists of the average colour of each of its children.
The deeper we visit in the tree, the more the detail of the image.
Quadtrees are also implemented in searching for nodes in a two-dimensional area. For instance, if we wanted to compute the closest point to given coordinates, we can do it implementing quadtrees.
The insert functions is implemented to insert a node into an existing Quad Tree. This function first verifies whether the given node is within the boundaries of the current quad. If it is not, then we immediately cancel the insertion. If it is within the boundaries, we choose the appropriate child to contain this node based on its location. This function is O(Log N) where N indicates the size of distance.
The search function is implemented to locate a node in the given quad. It can also be edited to return the closest node to the given point. This function is applied by taking the given point, comparing with the boundaries of the child quads and recursing. This function is O(Log N) where N indicates the size of distance.