An interactive explanation of quadtrees
jimkang.com
jimkang.com
I'm by no means an expert on them but here are some things worth knowing if you plan on using them:
1) The implementation shown is called a point region quadtree (pr quadtree) and subdivides the space equally for all divisions. This may seem like a neat approach until you consider what happens when there are two points very close to each other. Because you need each point to be in it's own node, you need to keep subdividing the region, which can result in a theoretically unbounded depth. There's a variant called compressed pr quadtree which handles this problem by removing all nodes that only have 1 non-empty child. This reduces the depth appropriately.
2) There is another strategy for dividing the space called point quadtrees (p quadtrees) which divides the regions at the point you are inserting. This gives an upper bound of the tree depth as the number of nodes inserted, which is still undesirable. To fix this, you have to choose the correct order for point insertion to obtain a well balanced tree with log_4(n) height.
3) The non-academic implementations I've seen do clever things like setting a maximal subdivision number and allowing multiple points within a leaf.
4) There are often alternatives to quadtrees that are simpler and usually effective enough such as subdividing the region into an mxn grid of equal proportion and using the grid squares as buckets for the elements that fall within them.
Spatial data-structures are kinda fun but can have gotchas.
Curious, did you use any other information or was this a wild guess?
As a side note, if anyone wants to go into more depth, Samet's "Foundations of Multidimansional and Metric Data Structures" (http://www.amazon.com/Foundations-Multidimensional-Structure...) is an extensive survey of a lot of spatial data structures.
It seems like you could balance as you went along in a similar fashion to balanced binary trees such as b-trees or AVL trees.
Couple of minor gripes, though. It encourages you to play with the first pair of tree/map, which involves a lot of scrolling (which is stolen and zooms if I accidentally hover the tree). This would've been a lot easier if I'd been encouraged to move on and see the side-by-side (or maybe omit the bigger versions completely).
Also, you asked my biggest question ("Why four children?") and then completely failed to answer it. This looks like it could be implemented trivially as a binary tree (twice as deep, of course). Why 4? Why not 2, or 8? Arguing "by definition" tells me nothing.
A different way of putting it is, a binary tree partitions a line, a quad tree partitions a plane. An octree (http://en.wikipedia.org/wiki/Octree) partitions a space, and so on.
For some cool variants also see k-d tree:
http://en.wikipedia.org/wiki/K-d_tree
And R-tree:
That would actually be a BSP tree, k-d tree or bounding volume hierarchy. A quad tree is a 2-d version of a trie.
Basically, you can treat a tree like an array.
This is the first time I have come across quad and oct trees, but I think the order statistic concept can be applied here.
[0] http://www.cs.cornell.edu/courses/cs211/2004su/slides/Topic2...
http://bl.ocks.org/patricksurry/6478178
Which also links:
http://bl.ocks.org/mbostock/4343214
I found the 'Voronoi Tessellation' to be really mind bending:
A description of Quadkeys would be great here too.
The quadkey can be thought of as a representation of the route to a point, i.e each time a rectangle is divided, each of its quadrants is assigned a letter A-D (or number 0-3) and the quad key for a point is the concatenation of those labels from the top of the tree down to (typically) an arbitrary depth.
If a quadkey is then used as an indexed field in a database, the question "All the points in a specific quadrant" is simply a prefix search
http://gamedev.stackexchange.com/questions/72392/handle-move...
I have neither mouse wheel nor touchscreen device, only a touchpad.