Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Later I looked at AVL trees... and they still give me a headache.

Why? From what I remember AVL trees were much easier to implement than B-trees. Especially if using recursion.



Insertion in AVL tree's is fairly simple and doesn't really have any cascades so they are quite predictable, deletions on the other hand cascades upwards with a bunch of different imbalances and thus rotations(and post rotation balances) to be accounted for.

Recently implemented them for an advanced hobby project and having a solid fuzzing tester in place really alleviated a lot of headaches in the long term since it was able to produce quite an exhaustive set of conditions.


B-tree deletions are quite complicated too, requiring stealing keys from either-side sibling or merging with either-side sibling.

In practice, I find that a B-tree implementation is 2 to 3× the length of an AVL tree impl.

I also fuzz-tested my implementations thoroughly. https://www.nayuki.io/page/avl-tree-list , https://www.nayuki.io/page/btree-set , etc.


Yeah, this is what I was thinking too. The rebalancing on AVL is a bit tricky but once you grok it, it is not that much code...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: