Блог пользователя proofbycontradiction

Автор proofbycontradiction, история, 8 лет назад, По-английски

In programming contests, I see that many of the codes that require an implementation of a balanced BST actually use a splay tree. Why do you use them over other trees that offer stronger guarantees such as AVL trees and Red Black?

For example, see this solution by tourist.

Are they that much faster than other trees (like quicksort or binary search trees)? Or do they have some interesting non-trivial properties that are especially useful? What I mean to ask is if there are questions where using a Splay Tree gives a much better result than using other kinds of trees.

  • Проголосовать: нравится
  • +23
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Faster than Treap, allows efficient Split / Merge operations, surely shorter than Red Black Trees and probably shorter than AVL Trees if you also want to add Split and Merge operations (which are a little more involved for AVL Trees)

I think this is definitely enough but I'm not aware of other advantages :)

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +43 Проголосовать: не нравится
»
8 лет назад, скрыть # |
 
Проголосовать: нравится +26 Проголосовать: не нравится

There are quite a few applications such as merging (as in merge sort, not as in concatenation) and link-cut trees, where splay trees make it much easier to get amortized runtime instead of . (See also the section on finger search on wikipedia.)

You usually don't mind the fact that the runtime bound is only amortized. The notable exception to this is if you want persistent search trees.

Regarding speed, it would be interesting to see a micro-benchmark on different types of balanced trees. (Both with and without parent pointers.)