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
Related
What is the maximum difference between any two leaves in an AVL tree? If I take an example, my tree becomes unbalanced, if the height difference is more than 2(for any two leaves), but the answer is the difference can be any value. I really don't understand, how this is possible.Can anyone explain with examples?
The difference in levels of any two leaves can be any value! Definition of AVL describes height difference only on two sub-trees from one node.
So you need to fill subtrees with equal height then add new nodes just to create that single node difference. But nobody said that that subtree doesn't contain some subtrees with the exact same definition. Of course tree is selfbalanced but if we'll be that accurate to not touch it's balance then we can create any height difference between some leaves.
Example with leaf 24 on level 3 and leaf 10 on level 6:
According to the explanation in this Wikipedia article, the balancing operations in an AVL tree successfully aim at rearranging the tree such that the height of any two leaves differs no more than one. This is the key property of the data structure which makes the retrieval of nodes efficient (namely logarithmic in the number of nodes of the tree, as a path from the root to a leaf is traversed in the worst case).
Find an example AVL tree such that removing a single (specific) value
from the tree causes rebalancing to occur starting at two different
nodes.
I have this as my homework question. I know what an AVL tree is, but I don't understand the above question. Can someone shed some light?
Does rebalancing at two different nodes mean that two rotations are needed to fix the tree?
An AVL rebalance operation is a time when a particular node needs to have either a single or double rotation applied to correct the imbalance in the tree. I think the question is asking you to find a case where doing a single or double rotation within an AVL tree locally fixes the balance, but then requires a rebalance operation to be performed at a node higher up in the tree.
Hope this helps!
What's wrong with the heights of the left and right children of some node differ being by 2?
This is my first encounter with AVL trees, and I can't seem to understand why it is a must?
Really, what's wrong with the children being different by 2?
Regards
By definition, a balanced binary tree can only differ by one. If you look at the algorithms that operate on the AVL trees, you'll see that this property is always maintained.
While it's possible to make some sort of data structure where the height differs by +- 2 at most, there is not real benefit in doing so. By leaving it as +- 1, you create a simpler, self-balancing data structure.
Well that's the concept of an AVL tree, the height of left and right childs must not differ by at most one.
From Wikipedia
In an AVL tree, the heights of the two child subtrees of any node
differ by at most one.
Since it's balanced, this make the search 0(logn), so it's faster than a non-balanced binary tree, where all the elements could be on the left, making it 0(n)
I'm trying to learn about Trees and their uses. One part of my class slide said that one definition of a tree is:
The height (maximum distance) of a tree is the maximum level among all of the nodes in the tree.
Node quit sure what that means, can anyone explain? Thanks
The height of a tree is the length of the longest downward path to a leaf from the root.
We are dealing with a Most similar neigthbour algorithm here. Part of the algorithm involves searching in order over a tree.
The thing is that until now, we cant make that tree to be binary.
Is there an analog to in order traversal for non binary trees. Particularly, I think there is, just traversing the nodes from left to right (and processing the parent node only once?")
Any thoughts?
update
This tree will have in each node a small graph of n objects. Each node will have n children (1 per each element in the graph), each of which will be another graph. So its "kind of" a b tree, without all the overflow - underflow mechanics. So I guess the most similar in order traversal would be similar to a btree inorder traversal ?
Thanks in advance.
Yes, but you need to define what the order is. Post and Pre order are identical, but inorder takes a definition of how the branches compare with the nodes.
There is no simple analog of the in-order sequence for trees other than binary trees (actually in-order is a way to get sorted elements from a binary search tree).
You can find more detail in "The art of computer programming" by Knuth, vol. 1, page 336.
If breadth-first search can serve your purpose then you can use that.