Treap (Cartesian Tree)
Posted by vismit2000 3 days ago
Comments
Comment by modulovalue 19 hours ago
Something that's not mentioned in that article is that you can maintain any monoid efficiently over balanced trees, not just the subtree size (aka you need an identity element and an associative operation). Most widely known monoids are boring, but there are more interesting monoids. Interval trees can be implemented as an augmentation using a monoid (this concept is more widely known as augmenting a tree). Range min max augmentations can be used to implement succinct trees (this comes from Sadakane's work on succinct trees, he didn't describe it as a monoid IIRC, but it turns out it is one).
By looking at it from a monoid angle, the specific balanced tree can be abstracted away. Treaps are VERY easy to implement, but the monoids apply to any n-ary balanced trees. There was an article a few days ago about very efficient B-Trees, but from what I've seen they did not support general purpose augmentations, probably because the implementation would have to be partially evaluated to be optimal while being general.
In any case, cool stuff and totally under-explored in my opinion. I hope LLMs will help us become optimal in this area one day and help us automatically select an optimal augmentation and balanced tree. There are so many problems that can be sped up by balanced trees and augmentations.
Comment by dooglius 16 hours ago
Comment by lindig 18 hours ago
The correct name is Raimund Seidel https://en.wikipedia.org/wiki/Raimund_Seidel
Comment by cyanydeez 18 hours ago
Comment by rbehrends 21 hours ago
These days, where an agent can just write you an AVL tree, red-black tree, or B-tree library in under a minute, it probably matters less.
Comment by ncruces 19 hours ago
What I like about immutable treaps is that, if you using hashing rather than randomness, you can achieve O(1) equality for entire trees.
Unfortunately, my current language of choice makes hash consing too slow.
Comment by vismit2000 1 day ago
Comment by sparkilyshpark 22 hours ago
Comment by hjadoui 18 hours ago