I read Chris Okasaki's "Red-Black Trees in a Functional Setting" (1993) paper ov...
dave @dthompson@toot.cat
I read Chris Okasaki's "Red-Black Trees in a Functional Setting" (1993) paper over the weekend and it's brilliant. Pretty much all the resources on red-black trees out there describe very imperative algorithms but this paper describes a functional insert algorithm that is much simpler than anything else I've seen.
https://www.cs.tufts.edu/~nr/cs257/archive/chris-okasaki/redblack99.pdf
Unfortunately, Okasaki conveniently leaves out deletion! Red-black tree deletion is mind bending! Thankfully I'm not the first person to notice this. Kimball Germane and Matthew Might published a functional pearl of their own in 2014: "Deletion: The curse of the red-black tree"
https://matt.might.net/papers/germane2014deletion.pdf
I'm reading about all of this in an effort to add the balancing properties of red-black trees to the discrete interval encoding trees (diets) in Martin Erwig's "Diets for fat sets" (1993):
https://web.engr.oregonstate.edu/~erwig/papers/Diet_JFP98.pdf
My microbenchmark is showing about a 10% improvement in set membership queries over the unbalanced version with a randomly generated large set. Maybe it's not worth all the effort but I don't really like implementing trees that *could* degenerate to O(n) query time.