News for hackers. Stuff that matters.
Re:An Interactive Explanation of Quadtrees by eutectic on Tuesday February 14, 2023 @06:14PM (#34797609)
I feel like quadtrees are almost never the best data structure for a given problem. The rare exception being HashLife.
Re:An Interactive Explanation of Quadtrees by convolvatron on Tuesday February 14, 2023 @06:37PM (#34797833)
what else would you use for spacial subdivision? bsp trees?
Re:An Interactive Explanation of Quadtrees by hobs on Tuesday February 14, 2023 @06:43PM (#34797882)
Why cant you use an N tree, what's special about 4?
Re:An Interactive Explanation of Quadtrees by ShredKazoo on Tuesday February 14, 2023 @09:06PM (#34799137)
Maybe having the struct size be constant allows for better space locality in memory? You never have to reallocate nodes, you can pack everything into an array.
Re:An Interactive Explanation of Quadtrees by taeric on Tuesday February 14, 2023 @09:29PM (#34799271)
I'm now very curious on this. My gut was more that it is 2^(number of dimensions) that is important here. As such, for a single dimensional storage of data, standard binary tree. Add in another dimension, but still want to halve the search space with every comparison, add another branch factor to the tree.

That said, this implies that for 3d space, you would want 8 way trees? But, I don't think I've ever heard of that being done/used.

Re:An Interactive Explanation of Quadtrees by ShredKazoo on Tuesday February 14, 2023 @09:40PM (#34799344)
A B-tree does in fact have >2 children for only a single dimension.
Re:An Interactive Explanation of Quadtrees by taeric on Tuesday February 14, 2023 @11:49PM (#34800217)
Right. But that is more to optimize cache/block reads, right? Been way too long since I've looked at many of those details. :)
Re:An Interactive Explanation of Quadtrees by ShredKazoo on Wednesday February 15, 2023 @03:46AM (#34801482)
Yeah pretty much, a node in a B-Tree is designed to fill a single page of memory
Re:An Interactive Explanation of Quadtrees by EliasLittle on Tuesday February 14, 2023 @09:38PM (#34799326)
8 way trees are used for 3D, they’re called Octrees.

https://en.wikipedia.org/wiki/Octree?wprov=sfti1

Re:An Interactive Explanation of Quadtrees by taeric on Wednesday February 15, 2023 @08:30AM (#34803520)
I'm now super amused with myself for not looking for "oct." Which, yeah, would have been the obvious prefix to look for.
Re:An Interactive Explanation of Quadtrees by corysama on Tuesday February 14, 2023 @10:29PM (#34799733)
In ray-tracing, people debate back and forth between kd-trees, octrees, quad-AABB trees, oct-AABB trees, and I’m sure there are a few more.

I think quad-AABB has been the most popular option for a while now.

Re:An Interactive Explanation of Quadtrees by sudosysgen on Wednesday February 15, 2023 @01:40AM (#34800797)
Generally the most popular is a BVH system between objects and a kd-Tree within objects, in my experience.
Re:An Interactive Explanation of Quadtrees by boppo1 on Wednesday February 15, 2023 @05:31AM (#34802068)
I'm a noob to DS&A, but I'm writing a little add-on for Blender and have come up against BVH and kd-trees. What makes one more popular for 'within objects' and the other for 'between'?
Re:An Interactive Explanation of Quadtrees by sudosysgen on Wednesday February 15, 2023 @12:17PM (#34807153)
BVHes handle sparsity and very large scenes with variable density very well, so they are good to be able to see which objects you might intersect. kd-Trees are much better for objects because they handle the high density of geometry very well and are thus very effective if you want to test against a million triangles in close proximity, for example.
Re:An Interactive Explanation of Quadtrees by boppo1 on Thursday February 16, 2023 @12:52PM (#34822416)
Thanks!
Re:An Interactive Explanation of Quadtrees by taeric on Wednesday February 15, 2023 @08:31AM (#34803525)
So many things to read up on, now! :D Thanks for the pointers!
Re:An Interactive Explanation of Quadtrees by misja111 on Wednesday February 15, 2023 @03:13AM (#34801304)
> My gut was more that it is 2^(number of dimensions) that is important here.

Yes, it's just binary search but applied to every dimension.

Re:An Interactive Explanation of Quadtrees by taeric on Wednesday February 15, 2023 @08:29AM (#34803514)
This was my thinking, exactly. I have not tried implementing one before.
Re:An Interactive Explanation of Quadtrees by eutectic on Tuesday February 14, 2023 @06:44PM (#34797899)
Something adaptive. Maybe AABB trees depending on the context.
Re:An Interactive Explanation of Quadtrees by MrLeap on Wednesday February 15, 2023 @08:59AM (#34803817)
I'm a fan of spatial hash grids for most of the things I would consider quadtrees for.

It's simpler to reason about and there's no monkeying around with trees when you add an element or move one around.

Re:An Interactive Explanation of Quadtrees by jandrewrogers on Tuesday February 14, 2023 @07:51PM (#34798530)
Quadtrees have the distinction of being the simplest space decomposition data structures that also manifest every pathology and difficulty of said data structures. It is a great data structure to study for this reason.

While they work well in some applications, many people opt for one of two algorithm selection strategies as an alternative. First, select a more narrowly tailored algorithm that fits their application domain and requirements but avoiding many of the pathologies, giving up some generality but retaining the simplicity. R-trees are arguably an example of this (albeit a bit more complex). Second is to use more exotic and complex space decomposition algorithms that are significantly more difficult to implement in practical systems but retain at least as much generality while mitigating or eliminating most pathological cases.

A quadtree isn't a local maxima in the algorithm phase space in the same way a b+tree is.

Re:An Interactive Explanation of Quadtrees by heisjustsosmart on Saturday February 18, 2023 @01:35PM (#34849630)
What pathology and difficulty?

"Second is to use more exotic and complex space decomposition algorithms"

these being what

What is this: "algorithm phase space"

Re:An Interactive Explanation of Quadtrees by jandrewrogers on Sunday February 19, 2023 @05:54PM (#34862731)
Quadtrees have exceptional scalability but also notorious issues with space complexity and selectivity for some common data models.

Space complexity is unbounded space for non-scalar types, hence why r-trees are used in practice for things like polygons. They have poor search selectivity as a function of index size for many data models, quasi-monotonic data like time-series being an extreme case. In alternative algorithms that try to preserve scalability, these issues are handled via a combination compressing out non-selective branches of the index, for which there are many techniques in literature with various tradeoffs when applied to space decomposition, and by embedding the data model into a higher dimensionality index of a similar type, allowing the algorithm to be selective on additional properties of the data not for the purpose of search but to cause the data to organize in such a way that it is more resistant to manifesting selectivity and space complexity issues.

There are hundreds of described spatial indexing algorithms in literature that tackle the selectivity and space complexity issues in various ways, often by sacrificing the natural scalability of quadtrees in various ways. The space of possible algorithm designs with interesting tradeoffs is very large but bounded. Hanan Samet's canonical text on the algorithm design space weighs in at over a thousand pages and still doesn't cover the full scope of notable algorithm design clusters in public literature.