24

I was reading the article from Steve Yegge about singletons. In it he mentions his teacher told him AVL Trees were evil. Is it just that red and black trees are a better solution?

Jonas
  • 97,987
  • 90
  • 271
  • 355
Chap
  • 2,700
  • 23
  • 31

6 Answers6

19

Evil from what point of view?

Like always: there are no bad tools, only bad craftsmen.

In my memory, AVL trees have slower insertion/removal but faster retrieval than Red/black. Mainly because of the balance algorithm.

Ionuț G. Stan
  • 160,359
  • 18
  • 179
  • 193
Antoine Claval
  • 4,645
  • 6
  • 39
  • 68
  • 4
    Exactly. If you need a write-once–read-many map, AVL trees are hard to beat. In my opinion, they are also easier to implement correctly. – erickson Sep 08 '09 at 15:39
  • 5
    A write-once–read-many map sounds more like a sorted array to me... A write-rarely–read-many map sounds more than an AVL tree. However even in those cases be sure to consider a sorted array. The constant costs are considerably lower, so you will need many entries before an AVL tree outperforms both red/black tree and a sorted array. – B.S. Sep 08 '09 at 16:43
  • 3
    AVL trees are however highly comprehenable. IME, RB trees are not understood by their implementors - they are merely following the rules; they do not genuinely comprehand what is going on, conceptually. –  Oct 12 '09 at 13:28
8

No, AVL trees are certainly not evil in any respect. They are a completely valid self balancing tree structure. They have different performance characteristics than Red-Black trees certainly and typically these differences lead to people choosing a red-black tree over an AVL tree. But this does not make them evil.

JaredPar
  • 673,544
  • 139
  • 1,186
  • 1,421
4

I'm sure that AVL trees are evil in the same way that GOTO is evil or BUBBLE SORT is evil.

Algorithms aren't evil, but algorithms also don't jump up and down to tell you when they are appropriate either.

Dave
  • 1,041
  • 1
  • 9
  • 18
2

Here's a lot of info about the differences between Red-Black and AVL-Trees:

http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=22948

and a paper comparing the different structures:

http://www.stanford.edu/~blp/papers/libavl.pdf

In short - AVL is faster to search, Red-Black faster to insert.

Tobias Langner
  • 10,162
  • 5
  • 42
  • 72
  • The fogcreek link is bad. The content is misleading. AVL trees do not require O(log n) rotations for rebalancing. Max 2. – Jesse Sep 13 '10 at 12:48
1

Splay Trees are much cooler. :)

Macke
  • 22,774
  • 6
  • 76
  • 108
1

No, they aren't evil, only a bit tricky to program.

AVL Trees http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_avl.aspx

Red Black tree link from there too.

Eric D.
  • 11
  • 1