AVL tree rotation example clarification - data-structures

Now, I am learning AVL tree data structure from a book and here's one example which I have a difficulty to understand:
Can anyone explain the process of rotation here?

I am not sure about your example but I think it is wrong
AVL tree is height balanced binary search tree (which is not in your example, AUG should be inserted on right hand side of MAY not left)
anyways in AVL tree LR rotation with an example could be like this,
for good animation you can see ,

Related

When is a red-black tree left leaning?

When is a red-black tree left leaning ?
Does it just mean that on the letf side from the root are more nodes then on the right side?
I cant really grasp the definition what left leaning really means somewehre I also read that its related to the 2-3-4 Tress.
Thanks for your help
It means that a black node is limited to having a maximum of one red child and if it has that red child it will appear as the left child. Left-leaning red-black trees model a 2-3 tree instead of a 2-3-4 tree the way the classic red-black tree does.

Property of AVL tree

I’m doing some exercises about AVL tree
The following two question belong are both false
The absolute value of height difference of any subtrees on the same level is at most one
Isn’t it a property of AVL tree?
A deletion needs at most two rotation operations to preserve an AVL tree to be a height-balanced tree
As I know the most operation when del/insert a node is double rotations.
Where are the wrong points?
I’m not native speaker, thanks in advance
By absolute value of height difference, do you mean difference between any two leaves of the sub-trees?
If yes, you can find the answer here: https://stackoverflow.com/a/28966528/11101571

Is kd-tree always balanced?

I have used kd-tree algoritham and make tree.
But i found that tree is not balanced so my question is if we used kd-tree algoritham then that tree is always balanced if not then how can we make it balance ?.
We can use another algoritham likes AVL or Red-Black for balancing kd tree ?
I have some sample data for that i used kd-tree algoritham but that tree is not balanced.
(14,31), (15,32), (17,42), (16,44), (18,52), (16,62)
This is a fairly broad topic and the questions themselves are kind of general.
Hopefully this will give you some useful insights and material to work with:
Kd tree is not always balanced.
AVL and Red-Black will not work with K-D Trees, you will have either construct some balanced variant such as K-D-B-tree or use other balancing techniques.
K-d Tree are commonly used to store GeoSpatial data because they let you search over more then one key, contrary to 'traditional' tree which lets you do single dimensional search. GeoSpatial data certainly cannot be represented in single dimension.
Note that there are also specialized databases working with GeoSpatial data so it might be worth checking if the overhead could be shifted to them instead of making your own solution: Although i don't have much experience with this, maybe it is worth checking the postgis.
postgis
Here are some useful links showing how to build balanced K-D tree variant and usage of K-D trees with Spatial data:
balancing K-D-Tree
K-D-B-tree
spatial data k-d-trees
It depends on how you build the tree.
If built as originally published, the tree will be balanced, i.e. only at the leaf level it will have at most a height difference of 1. If your data set has 2^n-1 elements, the tree will be perfectly balanced.
When constructed with the median, then half of the objects must be on either branch of the tree, thus it has minimal height and is balanced.
However, this tree cannot be changed then. I am not aware of an insert or remove algorithm that would preserve this property, but YMMV. I bet there are two dozens of kd-tree extensions that aim at rebalancing and making insertions/deletions more effective.
The k-d-tree is not designed for changes, and will quickly lose efficiency. It relies on the median, and thus any change to the tree would worst-case propagate through all of the tree. Therefore, you need to allow some tolerance in the tree quality to support changes. It appears to be a common approach to just keep track of insertions/deletions and rebuild the tree eventually. You cannot combine it with red-black-trees or AVL-trees, because data with more than 1 dimension is not ordered; these trees only work for ordered data. Upon rotation of the tree the splitting axis changes; and there may be elements in either half that suddenly would need to move to the other branch. This does not happen in AVL or red-black trees.
But as you can imagine, people have published several indexes that remain balanced. Such as k-d-b-trees, and R-trees. These also work better for large data that needs to be stored on disk.
In order to make your kd-tree balanced use median value.
(14,31), (15,32), (17,42), (16,44), (18,52), (16,62)
In the root choose median of x-cordinates [14,15,16,16,17,18] which is 16,
So all the elements less than 16 goes to left part of the tree and
greater than or equal to goes to right side of tree.
as of now,
left part tree consists of [14,31],[15,32] ,now for y-axis find the median for [31,32]
so that the tree is balanced

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.

Updating the balancing factor of AVL tree nodes

I am learning about AVL trees, and I know how to do all of the rotations, but the one thing I need to know is how to make it so that after each insertion or rotation the balancing factors of the nodes are updated.
Thanks!
Just have a look at an existing AVL tree implementation. This is one I wrote originally for Hypersonic SQL, it is still used as part of my H2 database:
TreeNode
TreeIndex
TreeCursor

Resources