I'm not very good with evidence, and I'm sure there are holes down there, but maybe it will cause something positive.
To perform k spins on a minimized AVL tree after removing a node, the following conditions must be met:
- The node target must exist in the 4-node subtree.
- The node target must either be on a short branch, or it must be the root of a subtree and be replaced by a leaf of a short branch.
- Each node in the pedigree of the root of the target subtree should be slightly out of balance (balance ratio +/- 1). That is, when a balance factor of 0 occurs, the rotation chain terminates.
The height and number of nodes of a collapsed tree are calculated using the following equations.
Let H (k) = the minimum height of the tree subjected to k rotation.
H(k) = 2k + 1, k > 0
Let N (h) = the number of nodes in the AVL tree of height h (min-node) of height h.
N(0) = 0 N(1) = 1 N(h) = N(h-1) + N(h-2) + 1, h > 1
Let F (k) = the minimum number of nodes in the tree affected by k rotations.
F(k) = N(H(k))
(eg:)
k = 1, H(k) = 4, N(4) = 7 k = 2, H(k) = 6, N(6) = 20
Proof (such as it is)
Minimum height
Removing can cause rotation only for trees with 4 or more nodes.
- The 1 node tree must have a balance factor of 0.
- A tree of two nodes should have a balance factor of +/- 1, and deletion leads to a balanced tree of 1 node.
- A tree of three nodes must have a balance factor of 0. Removing a node leads to a balance factor of +/- 1 and no rotation occurs.
- Therefore, removal from a tree with less than 4 knots cannot lead to rotation.
The smallest subtree for which 1 rotation occurs when deleting is 4 nodes with a height of 3. Removing the node on the short side will rotate. Similarly, removing the root of a node using node on the short side as a replacement will result in rotation. It doesn't matter how the tree is configured:
BB Removal of A or replacement of B with A / \ / \ results in rotation. No rotation occurs ACAD on removal of C or D, or on replacement \ / of B with C. DCCC Removal of D or replacement of C with D / \ / \ results in rotation. No rotation occurs BDAD on removal of A or B, or on replacement / \ of C with B. AB
Removing a 4 node from a tree results in a balanced tree with a height of 2.
. / \ . .
To perform the second rotation, the target tree must have a brother of height 4, so that the root balance coefficient is +/- 1 (and therefore has a height of 5). It does not matter whether the affected tree is located to the right or left of the parent, as well as the layout of the brother's tree (that is, the H3 child from H4 can be left or right and can be any of the 4 orientations above, while the child H2 can be one of two possible orientations - this requires confirmation).
_._ _._ / \ / \ (H4) . . (H4) / \ / \ . . . . \ \ . .
It is understood that the third rotation requires that the grandparents of the affected tree are also unbalanced by +/- 1, and the fourth requires that the great-grandmother be unbalanced by +/- 1, etc.
By definition, the height of a subtree is the maximum height of each branch, plus one for the root. One brother must be 1 above the other in order to achieve an imbalance of +/- 1 at the root.
H(1) = 3 (as observed above) H(k) = 1 + max(H(k - 1), H(k - 1) + 1)) = 1 + H(k - 1) + 1 = H(k - 1) + 2 ... Inductive proof leading to H(k) = 2k + 1 eludes me.
Minimum nodes
Consequence
- The minimum number of nodes is not necessarily the maximum in large trees. To wit:
Remove A from the next tree and note that the height does not change after rotation. Therefore, the balance ratio in the parent would not change and no additional rotation would occur.
BBD / \ \ / \ AD => D => BE / \ / \ \ CECEC
However, in the case k = 2, it does not matter if H (4) is minimized here - the second rotation will still take place.
_._ _._ / \ / \ (H4) . . (H4) / \ / \ . . . . \ \ . .
Questions
- What is the position of the target subtree? It is clear that for k = 1 it is the root, and for k = 2 it is the left if the root balance coefficient is -1 otherwise it is right. Is there a formula for determining the position for k> = 3?
- What are the maximum nodes a tree can contain to cause k rotations? Is it possible to have an intermediate node in a pedigree that does not rotate, although its parent?