Hacker News new | ask | show | jobs
by crest 10 days ago
Binary trees have worse cache locality. The cost of accessing memory has grown so much compared to computation that supposedly slower "heavy weight" data structures are worth it now (as in the last 10-20 years).
2 comments

A b-tree isn't a binary tree. B doesn't officially stand for binary either, see History[0].

[0] https://en.wikipedia.org/wiki/B-tree

I'm guessing their point is unlike binary trees which have two children per node, B trees can have as many children per node is best for cache locality/SIMD/etc. Which despite being "heavyweight" (wasted space if not all children per node are occupied) is faster in practice because it's cheaper to preload large unused blocks to cache rather than only access memory when it is needed.
Every node in a binary tree needs a value and two child pointers, though. That's asymptotically almost twice as many child pointers per value as a B-tree has.
It’s a good thing this article isn’t about binary trees then.
The comment I replied to claimed that B-trees are "heavyweight" compared to binary trees. I thought it worth pointing out that the claim is only true for quite small trees.
A binary tree would be strictly worse than a skip list for cache line efficiency. Seeing as how skip lists were invented to improve on binary tree cache behavior.