- What is difference between AVL trees and splay trees?
They are similar in structure and the operations we call on them. The difference is that in splay trees, after each operation, we try to keep the tree almost perfectly balanced so that future operations take less time.
- On what basis do we select these tress?
Splay trees are always better than binary search trees when, your application deals with a lot of data in the tree but, will need access to a subset of the data very frequently than others. In this case the data you access frequently will come near the root as a result of the splay. Also, any node can then be accessed with less time than before.
As a general rule for selecting these trees, if you need "Average" log(n) time over a period of tree operations then use splay tree. Binary tree cannot guarantee this.
- What are positive's and negative's of these trees?
Positives for both is that you get around log(n) in both these data structures theoretically.
As mentioned splay trees have average log(n) over a number of operations. This means that, maybe you got n time complexity for an operation atleast once in that set. But this will be compensated when accessing the frequent items.
The negative of the binary search tree is that, you need to be lucky to have log(n) always. If the keys are not random, then the tree will reduce to a list like form with only one side.
- What are the performances of these trees in terms of big O notation?
Splay tree Log(n) on Average for a group of tree operations
Binary tree Log(n) only if your keys are going in random.
The results on the runtime are obvious here.
You can see the runtime difference in searching with and without splaying.