Quadtree (Partition Trees)

Quad-tree are partition trees:

  • organize space to facilitate efficient multidimensional search
    • internal nodes are associated with spatial regions
    • actual dictionary points stored only at leaves quad-tree and kd-Tree.

We have points in the plane. We need a bounding box : a square containing all points. Basically, side length needs to be a power of .

Structure:

  • Root of the quadtree is associated with region
  • If contains or points, then root is a leaf that stores point.
  • Else split: Partition into four equal subsquares (quadrants)
  • Partition into sets of points in these regions.
    • [convention]: points on split lines belong to right/top side
  • Recursively build tree for points in region and make them children of the root

Quadtree Dictionary Operations

  • : Analogous to BST and Tries
  • :
    • Search for the point, then
    • Split the leaf while there are two points in one region
  • :
    • Search for the point
    • Remove the point
    • If its parent has only one point left: delete parent (and recursively all ancestors that have only one point left)

Question: why do i delete the parent that has only one point left?

Insert example:

I don’t understand why we put Point10 over there and extend the child P6 to .

There are two cases for :

  • First perform search
  • Two cases:
  1. search finds a leaf storing one point
    • we need to repeatedly split the leaf while there are two points in one region. since if we insert, there will be two points in the region, so we need to split that subtree until it has one point in each region.
  2. search finds an empty subtree
    • then we can just add in the point we want to insert since there are no points there
    • expand empty subtree into a leaf storing insertion point

Quadtree Range Search:

Basically, if the region is not in what we are looking for A, we return. Don’t go down. If it’s in the region we must continue the search in children. If it’s a leaf and the point stored is in the region A we are looking for, we return the point.

Note

We assume here that each node of the quadtree stores the associated square. Alternatively, these could be re-computed during the sesarch (space-time tradeoff).

Note

The green outlines are indicating which actual points are returned, whereas the green filled node are ones whose region is fully inside the search area – if a green filled node itself contains a point, it will be outlined and returned, otherwise all of its children are also filled green and follow the same rules recursively.

Range search analysis:

  • Running time is number of visited nodes + output size
  • No good bound on on number of visited nodes
    • may have to visit nearly all nodes in the worst case
    • worst-case

Quad-tree Analysis

What is the height of a quadtree?

  • can have very large height for bad distributions of points
  • example with just three points, also possible with only two points
  • can make height arbitrarily large by moving red points closer together

Quad-tree splits without knowing where the points are.

Height of quad-tree is .

Operations depend on height of tree and the number of points. Number of nodes. Space potentially wasteful, but good if points are well-distributed (not all close together).

Spread factor: We prove

In the course notes textbook, it says that the we cannot give a bound on the run-time better than the size of the quad-tree, which is .

  • In worst case, height
  • In any case, height
  • Complexity to build initial tree: worst-case

Questions

Suppose we have a set of 2D points . What is the spread factor of the points in ?

  • 4

Quadtrees divide the 2-dimensional plane into quadrants by splitting a bounded region along lines parallel to the and axis. If this idea is extended into 3-dimensions, each internal node would have 16 children.

  • False, it would be an Octree, in 3-dimensional space, each internal node would need to be divided into eight octants, not sixteen. Since you split 4 and 4 again when it’s 3d.

If points are chosen correctly, a quadtree of any height can be created containing only 3 points.

  • True. How?

Suppose we have a Quadtree of height 3 constructed with initial side length . What is the new maximum height of the tree if we insert a point where and ? (You may assume that the coordinates are integers and the minimum distance between two points is and that .)

  • , why?

Suppose a quadtree is built using points , where and all points have coordinates in . If there is a pair of points at distance of each other, then the spread factor is .

  • True, how? Why?

Consider a square region of size by and a set of distinct points within the region that all have integer coordinates. What is the maximum number of levels that can be in the corresponding quadtree?

  • 5 levels, but why?