How can I convert a AVL tree to splay tree? - data-structures

I've got a generic c++ AVL tree and I'd like to know if it's possible (and not too complicated) to convert my AVL into a Splay tree or is it more efficient to program a Splay tree from zero

There is no such thing as a "splay tree", in the sense that the splay algorithm does not depend on any additional metadata nor does it impose any constraint on the tree structure. Any arbitrary binary tree can be used with the splay algorithm.
So you can "convert" an AVL tree simply by dropping or ignoring the AVL-specific per-node metadata.

Related

Splay tree: does an inorder traversal look at nodes in increasing order for a splay tree?

I just finished an exam on this, where I used an inorder traversal to check correct node order in one of my splay trees. Is this valid?
Yes, in-order traversal accesses a splay tree's elements in increasing order.
By the definition of a splay tree in the original article:
The splay tree, (is) a self-adjusting form of binary search tree
So, a splay tree is just a regular binary search tree by structure, which is all that is required for in-order traversal to access elements in increasing order. Apart from that, operations along the search path of a splay tree modify the structure, but they do so in a way which doesn't violate the binary search tree invariants.

Determining if a binary search tree can be constructed by a sequence of splay tree insertions

A splay tree is a type of self-adjusting binary search tree. Inserting a node into a splay tree involves inserting it as a leaf in the binary search tree, then bringing that node up to the root via a "splay" operation.
Let us say a binary search tree is "splay-constructible" if the tree can be produced by inserting its elements into an initially empty splay tree in some order.
Not all binary search trees are splay-constructible. For example, the following is a minimal non-splay-constructible binary search tree:
What is an efficient algorithm that, given a binary search tree, determines whether it is splay-constructible?
This question was inspired by a related question regarding concordance between AVL and splay trees.
More details: I have code to generate a splay tree from a given sequence, so I could perform a brute-force test in O(n! log(n)) time or so, but I suspect polynomial time performance is possible using some form of dynamic programming over the tree structure. Presumably such an algorithm would exploit the fact that every splay-constructible tree of size n can be produced by inserting the current root into some splay-constructible tree of size n-1, then do something to take advantage of overlapping/isomorphic subproblems.

what is the meaning of lookup algorithm?

I am a bit confused a term "lookup algorithm of avl trees". When I have searched this in google, I see so many website with related about b-tree not avl tree.
So, Is b-tree algorithm equal lookup algorithm of avl tree ?
If not, what is "lookup algorithm of avl tree" ? Moreover, what is the meaning of "lookup algorithm"? Please give me a link, of course if possible.
b-tree is a data structure - a generalized binary tree.
A lookup algorithm is an algorithm used to lookup values in the data structure. It is how you decide to find items in the data structure.
An avl tree is a type of b-tree (in the abstract).
The lookup algorithm is just the way that you look through the nodes in the tree to find a specific value.
An AVL tree is a self-balancing binary search tree, so the lookup algorithm of an AVL tree is the exact same as for a binary tree.
A B-tree is not the same thing as a binary tree, so it has a different lookup algorithm. The difference is that in a B-tree each node can have several values and more than two children, so the lookup algorithm follows the same basic principle as for a binary tree, but it's a bit more complex.
AVL tree is kind of balancing in the binary tree. B-tree is abbreviation for "Bayer-tree" - a kind of multinode (exceeding 2) tree. So these algorithms are different, since look-up in B-tree takes also look-up over particular page

Comparison about balanced binary search trees

I've read some Q&As about self-balancing binary trees, but I'm not quite familiar with all of them.
The first one of them I got to know is AVL, the second is Red-Black tree.
There are something I don't quite understand: according to some books and articles, AVL can perform searching a little bit faster than Red-Black tree, well, this is understandable.
Then what's Red-Black tree's edge over AVL?
In AVL, probably after each insertion, we have to check for balance, but in Red-Black tree we don't have to do something like that frequently, right?
PS:
I search SO for something similar, but I didn't get satisfying answer.
Hope some friends can give me a detailed comparison of self-balancing trees.
An AVL tree has the following property: from each node, the difference in height of the left and the right subtree is at most 2.
In a red-black tree, on the other hand, the height of the left or right subtree of any node is at most twice the height of the other tree. That is, they differ at most by a factor of 2.
This shows intuitively that lookup is indeed faster in an AVL tree on average.
However, when inserting or deleting a node, we have to rebalance the AVL tree more often, to preserve the much stricter height invariant (on the other hand, rebalancing in a red-black tree is algorithmically much more complicated). This means that in practice, a red-black tree may perform much better than an AVL tree, in particular when it’s often changed.

Balanced Binary Tree

What is the name of the binary tree (or the family of the binary
trees), that is balanced, and has the minimum number of nodes
possible for its height?
balanced binary tree
(data structure)
Definition: A binary tree where no leaf is more than a certain amount farther from the root than any other. After inserting or deleting a node, the tree may rebalanced with "rotations."
Generalization (I am a kind of ...)
binary tree.
Specialization (... is a kind of me.)
AVL tree, red-black tree, B-tree, balanced binary search tree.
Aggregate child (... is a part of or used in me.)
left rotation, right rotation.
See also BB(α) tree, height-balanced tree.
-- http://www.itl.nist.gov/div897/sqg/dads/HTML/balancedbitr.html
It is called Fibonacci tree
AVL is a balanced tree with log(n) height (this is the lowest height possible for binary tree).
Another implementation of a similar data structure is Red Black Tree.
Both trees implement all operations in O(log(n)).
AVL Tree is something that you have been looking for.
From Wikipedia:
In computer science, an AVL tree is a self-balancing binary search tree, and it is the first such data structure to be invented. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; therefore, it is also said to be height-balanced. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases, where n is the number of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.

Resources